MacroTrends Finance

FREEMIUM
By BeyzCoder | Updated 8 days ago | Finance
Popularity

9.4 / 10

Latency

1,939ms

Service Level

100%

Health Check

N/A

Back to All Discussions

convert to dataframe

Rapid account: Amira 123
amira123
a year ago

First of all, thanks for the amazing work.
I’m using python and I’d like to convert the output given by the API from a string type to an organized dataframe. How would you do that ? Thanks a lot.

Rapid account: Samimalek 0
samimalek0 Commented a year ago

import json
pydict = json.loads( x )

Rapid account: Amira 123
amira123 Commented a year ago

Hi Steven,

Sorry for the late reply. Yes that’s what I passed. But it’s fine, as it’s working just fine with the code mentioned before.

Rapid account: Stevenbaes
stevenbaes Commented a year ago

Hello Abe,

Hmmm, thats weird. Did you pass something like this?

stock = “O”
{“Years”:[“2021-12-31”,“2020-12-31”,“2019-12-31”,“2018-12-31”,“2017-12-31”,“2016-12-31”,“2015-12-31”,“2014-12-31”,“2013-12-31”,“2012-12-31”,“2011-12-31”,“2010-12-31”,“2009-12-31”],“Revenue”:[2080463000.0,1647087000.0,1488163000.0,1327838000.0,1215768000.0,1103172000.0,1023285000.0,933505000.0,780209000.0,484581000.0,412360000.0,333437000.0,322550000.0],“Cost-Of-Goods-Sold”:[133605000.0,104603000.0,88585000.0,66326000.0,69480000.0,62865000.0,55352000.0,53871000.0,38851000.0,21306000.0,15457000.0,5805000.0,6443000.0],“Gross-Profit”:[1946858000.0,1542484000.0,1399578000.0,1261512000.0,1146288000.0,1040307000.0,967933000.0,879634000.0,741358000.0,463275000.0,396903000.0,327632000.0,316107000.0],“Research-And-Development-Expenses”:[0,0,0,0,0,0,0,0,0,0,0,0,0],“SG&A-Expenses”:[96980000.0,73215000.0,66483000.0,84148000.0,58446000.0,51966000.0,49298000.0,51085000.0,56881000.0,38123000.0,30954000.0,25311000.0,20946000.0],“Other-Operating-Income-Or-Expenses”:[-459789000.0,-466387000.0,-331177000.0,-292289000.0,-304590000.0,-240638000.0,-243639000.0,-220492000.0,-181732000.0,-126782000.0,-108311000.0,-94086000.0,-85727000.0],“Operating-Expenses”:[1622017000.0,1216640000.0,991621000.0,916217000.0,861824000.0,742547000.0,702152000.0,646238000.0,558395000.0,320319000.0,255811000.0,211038000.0,196575000.0],“Operating-Income”:[324840800.0,325844100.0,407956900.0,345295000.0,284464000.0,297760000.0,265780900.0,233396000.0,182963000.0,142956000.0,141092000.0,116594000.0,119532000.0],“Total-Non-Operating-Income/Expense”:[67563000.0,85355000.0,35679000.0,24643000.0,40898000.0,21979000.0,22243000.0,39205000.0,0,0,0,0,0],“Pre-Tax-Income”:[392404000.0,411199000.0,443636000.0,369938000.0,325362000.0,319739000.0,288024000.0,272601000.0,182963000.0,142956000.0,141092000.0,116594000.0,119532000.0],“Income-Taxes”:[31657000.0,14693000.0,6158000.0,5340000.0,6044000.0,3262000.0,3169000.0,3461000.0,2350000.0,1061000.0,1470000.0,1393000.0,677000.0],“Income-After-Taxes”:[360747000.0,396506000.0,437478000.0,364598000.0,319318000.0,316477000.0,284855000.0,269140000.0,180613000.0,141895000.0,139622000.0,115201000.0,118855000.0],“Other-Income”:[0,0,0,0,0,0,0,0,0,0,0,0,0],“Income-From-Continuous-Operations”:[360747000.0,396506000.0,437478000.0,364598000.0,319318000.0,316477000.0,284855000.0,269140000.0,180613000.0,141895000.0,139622000.0,115201000.0,118855000.0],“Income-From-Discontinued-Operations”:[0,0,0,0,0,0,0,2800000.0,65670000.0,17257000.0,17410000.0,15583000.0,12272000.0],“Net-Income”:[359456000.0,395486000.0,436482000.0,363614000.0,301514000.0,288491000.0,256686000.0,227558000.0,203634000.0,114538000.0,132779000.0,106531000.0,106874000.0],“EBITDA”:[1262935000.0,1027376000.0,1022965000.0,918587000.0,805890000.0,765200000.0,686949000.0,615460000.0,510400000.0,306656000.0,270587000.0,214401000.0,214160000.0],“EBIT”:[324840800.0,325844100.0,407956900.0,345295000.0,284464000.0,297760000.0,265780900.0,233396000.0,182963000.0,142956000.0,141092000.0,116594000.0,119532000.0],“Basic-Shares-Outstanding”:[414535000.0,345280000.0,315837000.0,289427000.0,273466000.0,255067000.0,235768000.0,218391000.0,191755000.0,132817000.0,126143000.0,105870000.0,103578000.0],“Shares-Outstanding”:[414770000.0,345415000.0,316160000.0,289924000.0,273937000.0,255624000.0,236209000.0,218768000.0,191782000.0,132885000.0,126189000.0,105943000.0,103581000.0],“Basic-EPS”:[870000.0,1150000.0,1380000.0,1260000.0,1100000.0,1130000.0,1090000.0,1040000.0,1060000.0,860000.0,1050000.0,1010000.0,1030000.0],“EPS—Earnings-Per-Share”:[870000.0,1140000.0,1380000.0,1260000.0,1100000.0,1130000.0,1090000.0,1040000.0,1060000.0,860000.0,1050000.0,1010000.0,1030000.0]}

Rapid account: Amira 123
amira123 Commented a year ago

Hi Steven,

I had an error “DataFrame constructor not properly called!” when directly passing it to pd.DataFrame(). The workaround was pd.DataFrame(eval()).
Thanks again,

Abe

Rapid account: Stevenbaes
stevenbaes Commented a year ago

Hello Abe,

I just got back from vacation that’s why my reply is late. I do not quite understand the return format you want.
The return if you do symbo=AMZN&formstyle=dataframe

it should return something like this:
{
Years : […],
Revenue : […],

}

if you pass this on a pd.Dataframe() this will be ready.

May I ask for visual diagram of the format you want?

Steven

Rapid account: Amira 123
amira123 Commented a year ago

Hi Steven,

Thanks for you reply. It seems that :
data.decode(“utf-8”)
is still a str type even if “dataframe” is chosen as formstyle.

I was more thinking about a dataframe with two indexes, say df[i][j], where “i” would be the index of the date and “j” would be the index of the metrics. For instance, if I wanted the quarterly “Other non-cash items” (from Cash statement) of AMZN at 2022-09-30 of the , I would retrieve it here : df[1][2]

Thanks for your help,

Abe

Rapid account: Stevenbaes
stevenbaes Commented a year ago

Hello Abe,

I added a new optional query parameter ‘formstyle’ if you want a ready dataframe format. tell me if it is alright or you want to add some suggestion to it.

Thank you

Rapid account: Amira 123
amira123 Commented a year ago

Hi Steven,
Yes that’s it, thanks for your help !
Abe

Rapid account: Stevenbaes
stevenbaes Commented a year ago

Hello,

Thank you very much, sorry for the late reply. So just to check you want the API to be given to in a ready dataframe format for pandas, right?

Join in the discussion - add comment below:

Login / Signup to post new comments