简体   繁体   中英

how can I get a df from a complex str?

I have got a str by using the requests.get(url), it is a huge text, the abbreviations are as follows:

[{"id":0001,"stock_id":"hk00688","stock_name":"abc"},
 {"id":0002,"stock_id":"hk00689","stock_name":"def"},
 {"id":0003,"stock_id":"hk00690","stock_name":"ghi"}]

I want to get the df as it:

id    stock_id   stock_name
0001  hk00688    abc
0002  hk00689    def
0003  hk00690    ghi

but I got two difficult points need to help:

1, it is a str but the "list of dict", I don't know how to deal with it;

2, when I change the str to "list of dict", Is there is a simple function that converts to df, instead of using a for loop?

The server's response is clearly JSON, which is very easy to parse:

response = requests.get(url)
df = pd.DataFrame(response.json())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM