Splitting down a data frame column from ib_insync - ib-api

I am reasonably new to python and am struggling to breakdown the below.
Stock(conId=3691937, symbol='AMZN', exchange='SMART', primaryExchange='NASDAQ', currency='USD', localSymbol='AMZN', tradingClass='NMS')
This is a row in a dataframe with the column header order_contract
how do i break this down into seperate columns with headers conId , symbol , exchange , primaryExchange , currency , localSymbol , tradingClass
and the rows 3691937 , AMZN , SMART , NASDAQ , USD , AMZN , NMS
Sorry this isnt a well formatted question i am new to stackoverflow. Thanks in advance

Assuming ib_insync contract object is what you showed, this should suffice:
df = pd.DataFrame([x.__dict__ for x in df.order_contract])

Related

Tableau Help! Adding calculated columns and D day filters

i am fairly new to tableau, i am working on app health attributes basically, like installs , uninstalls,re installs,logins and other levels such as l1 , l2, l3(the user goes on till which level basically)
there are two things that i basically need to do:
Add d filters like
when datediff(days, event_time, install_time) < 2 then D1,
when datediff(days, event_time, install_time) < 7 then D7,
when datediff(days, event_time, install_time) < 30 then D30
else null end as d_filter
so basically a drop down filter of D DAYS which applies to all the metrics.
Adding columns like l1/installs,l2/installs i have tried creating a calculated field but when i finally add that to the view , it shows 0 values( even when i tried to view the ratio in a new sheet it showed wrong calculations)
i am attaching the screenshots for both the things, any help would be greatly appreciated!!!

Data still appearing in Oracle BI report when I dont give any input in the parameter

I have made a BI report using Oracle SQL. When I give an input to the parameter field, I get data. But, when I leave the parameter field as empty without giving any input, still the data appears instead of disappearing. What changes should I do in the SQL or OTBI dashboard to clear this problem?
**SELECT
AIA.INVOICE_NUM
, AHA.RELEASE_REASON
, DECODE (AHA.HELD_BY,'5', (SELECT ALC.DISPLAYED_FIELD
FROM AP_LOOKUP_CODES ALC
WHERE ALC.LOOKUP_TYPE(+) = 'NLS TRANSLATION'
AND ALC.LOOKUP_CODE(+) = 'SYSTEM'),
AHA.HELD_BY) "HELD BY"
, DECODE (AHA.LAST_UPDATED_BY,'5', (SELECT ALC.DISPLAYED_FIELD
FROM AP_LOOKUP_CODES ALC
WHERE ALC.LOOKUP_TYPE(+) = 'NLS TRANSLATION'
AND ALC.LOOKUP_CODE(+) = 'SYSTEM'),
AHA.LAST_UPDATED_BY) "RELEASE_BY_USER_NAME"
FROM
AP_HOLDS_ALL AHA
, AP_INVOICES_ALL AIA
WHERE 1=1
AND AHA.INVOICE_ID (+) = AIA.INVOICE_ID
AND (AIA.INVOICE_NUM IN (:INVOICE_NUM) OR COALESCE(NULL,:INVOICE_NUM) IS NULL)**

xpath for getting table rows with missing cell images

I'm trying to use Xpath to grab in rows of a table containing images and text. Things work fine as long as images are present as on this 3rd table on this page. But when images are missing as in the table as on this page it doesn't work. I need to connect the image with the right row of table data.
Here's the type of xpath_query strings I've been using in google sheets, where A1 contains the url.
=importXML(A1,"//tbody//img/#src")
=importXML(A1,"//tbody//tr")
Thanks for any help.
Shorter alternative with XPath filtering (url in C2, formula in I27) :
=ARRAYFORMULA({{"figura:";IMAGE("https://www.patentati.it/"&IMPORTXML(C2;"//tr//img/#src|//tr[not(.//img)]/td[#class='domanda']"))}\QUERY(IMPORTHTML(C2;"table";1);"select Col2,Col3")})
Output :
Sidenote : I'm based in Europe. Formula for US locales :
=ARRAYFORMULA({{"figura:";IMAGE("https://www.patentati.it/"&IMPORTXML(C2,"//tr//img/#src|//tr[not(.//img)]/td[#class='domanda']"))},QUERY(IMPORTHTML(C2,"table",1),"select Col2,Col3")})
like this:
=ARRAYFORMULA(IMAGE("https://www.patentati.it"&TRIM(SUBSTITUTE(FLATTEN(
SPLIT(QUERY(IFNA(REGEXEXTRACT(QUERY(ARRAY_CONSTRAIN(IMPORTDATA(A1), 500, 1),
"where Col1 matches '.*zoomImage.*|.*rowspan.*'"),
"src=""(.+png)"), "♀♫"),,9^9), "♫")), "♀", ))))
and a whole table:
=ARRAYFORMULA({{"figura"; IMAGE("https://www.patentati.it"&TRIM(SUBSTITUTE(FLATTEN(
SPLIT(QUERY(IFNA(REGEXEXTRACT(QUERY(ARRAY_CONSTRAIN(IMPORTDATA(A1), 500, 1),
"where Col1 matches '.*zoomImage.*|.*rowspan.*'"),
"src=""(.+png)"), "♀♫"),,9^9), "♫")), "♀", )))},
QUERY(IMPORTHTML(A1, "table", 1), "select Col2,Col3", 0)})

SSRS Report Parameter causing problems

I am facing a weird problem with SSRS Report Parameters. Currently working on SSRS 2016 version. We Connect to SSAS Models and create Data_sets using DAX Queries in the Report.
Here is the sample DAX Query used in my report Dataset,
evaluate
summarize(
calculatetable(
('Field Measures',
PATHCONTAINS(substitute(
substitute(
substitute(
#Parameter_District
, "{ ", "")
, " }", "")
, ",", "|") , 'Field Location'[District]),
PATHCONTAINS(substitute(
substitute(
substitute(
#Parameter_City
, "{ ", "")
, " }", "")
, ",", "|") , 'Field Location'[City])
)
'Field Fact'[Field Interview Number],
'Occurred Date'[Date],
'Occurred Date'[Year]
))
I have two parameters (District and City) defined in this query and both the fields are coming from the same table 'Filed Location'.
The problem I am facing is that, this query works well if I remove the 2nd Parameter "CITY". But it fails when I include this in the query. for simplicity I have mentioned only 2 parameters here, but I have around 5 parameters coming from the same table which were working fine.
I am banging my head why this happens only when I include [CITY] Object in the parameter list and why it works good when I remove this. Literally I am out of my mind :(
Please suggest me some way to debug this issue.
Thanks a bunch.
Balaji
I got the solution for my issue, but I don't have a logical reason why it works.
Let me re-post the DAX Query that I was using in my report,
evaluate
summarize(
calculatetable(
('Field Measures',
PATHCONTAINS(substitute(
substitute(
substitute(
#Parameter_District
, "{ ", "")
, " }", "")
, ",", "|") , 'Field Location'[District]),
PATHCONTAINS(substitute(
substitute(
substitute(
#Parameter_City
, "{ ", "")
, " }", "")
, ",", "|") , 'Field Location'[City])
)
'Field Fact'[Field Interview Number],
'Occurred Date'[Date],
'Occurred Date'[Year],
"Field Count",[FieldInterview - Count]
))
If we observe the original code I post earlier and the one I posted now, there is one line difference between them. i.e. The Measure Value (Field Count). while formatting my question I removed this last line of code (by mistake).But then when I revisited my own question for any probable answers, I noticed this difference and I just tried to use the query by removing the above mentioned Measure value and it just worked like magic!!
So, I really did not understand how Measures, Joins and Parameters work internally. I am still open for any kind of discussion/inputs from experts here.
Thank you.
Balaji
Simple way , Instead of creating parameter using DAX , go for Filter
Create Main dataset1 (all requried fields including city column)
Create Dataset2 for parameter for example (get only city column in this dataset)
Create parameter using the Dataset2
then go to main dataset1 - properties - filter. - add column and parameter in the expression.
this will work

Query with sum many columns from same table with laravel query

This seems very easy query but can't translate it into laravel query. I have table orders there are two columns total_usd and total_gbp. I want to sum each column to get total of usd and total of gbp on the page.
This query is working in phpmyadmin and I got correct result
SELECT sum(order_total_usd) as usd, sum(order_total_gbp) as gbp FROM `orders`
In laravel I've tried this
$sumOrders = Order::select('sum(order_total_gbp) as gbp, sum(order_total_usd) as usd');
when I dd($sumOrders) I've one really huge output which almost cause browser to freeze.
Where is my mistake here?
You can try something like this
$sumOrders = Order::select( \DB::raw("sum(order_total_gbp) as gbp"), \DB::raw("sum(order_total_usd) as usd"))->get();
You can use selectRaw
$sumOrders = Order::selectRaw('sum(order_total_gbp) as gbp, sum(order_total_usd) as usd');
Except for one missed word, your code is OK. Add "Raw" after "select" as shown:
$sumOrders =
Order::selectRaw(
'sum(order_total_gbp) as gbp,
sum(order_total_usd) as usd'
);
Just replace "Order::select(...)" with Order::selectRaw(...).
Have a great day!

Resources