Попытка поместить текст, разделенный запятыми, в фрейм данных pandas

#python #pandas #api #csv

Вопрос:

У меня возникли проблемы с получением ответа API в формате csv в фрейм данных pandas. Основные функции pandas не работали для меня, но я не настолько продвинут. Это мой вызов API:

 response = requests.get('https://data.messari.io/api/v1/assets/ada/metrics/price/time-series?interval=1damp;format=csv')
res = response.text
print(res)


 

Мой результат следующий:

 timestamp,open,high,low,close,volume
2020-11-01T00:00:00Z,0.09286327819615646,0.09871727981858057,0.09202731479794192,0.09826071504858695,27953080.64663609
2020-11-02T00:00:00Z,0.09819001417519348,0.1003317811814748,0.09112084926053894,0.09226895555284524,41254254.75458492
2020-11-03T00:00:00Z,0.09234523461385429,0.09413545735889374,0.08773058304394568,0.09363476651518426,37144774.90253366
2020-11-04T00:00:00Z,0.09368190716929714,0.09633801612889291,0.09160839185728606,0.09555423612606477,48246578.290414825
2020-11-05T00:00:00Z,0.09559192052364425,0.09828817929479862,0.09088002118247013,0.09753833458793106,58030769.3704354
2020-11-06T00:00:00Z,0.09750162516589665,0.11083340645426493,0.09683186844528095,0.10914401884646008,93252158.61233637
2020-11-07T00:00:00Z,0.10924755625197062,0.11388205911133911,0.08966284049139546,0.10143836960554167,107305104.76963407
2020-11-08T00:00:00Z,0.10148894133039574,0.10844692744217106,0.09985655829775107,0.10663983278639419,48849754.244560465
2020-11-09T00:00:00Z,0.1065097500307075,0.11107389590719384,0.10129986579115952,0.10563273089345326,59259435.36708425
2020-11-10T00:00:00Z,0.10552883048672461,0.10923829156542778,0.10360318113619912,0.1060109344949761,52691927.84209388
2020-11-11T00:00:00Z,0.10612015902043635,0.10905674598943878,0.10510236488698135,0.10609106228443135,47573057.283371046
2020-11-12T00:00:00Z,0.10614360594393216,0.10681335846078742,0.10232194766438421,0.10465039188165146,42303387.305539705
2020-11-13T00:00:00Z,0.10441369045167594,0.10808572111163872,0.10390724729147677,0.10634723504620915,41347674.19876987
2020-11-14T00:00:00Z,0.10638599542224504,0.10730895582745185,0.10087699987198498,0.10411192508857087,38777070.87670336
2020-11-15T00:00:00Z,0.10410694352784117,0.10528841825095998,0.09801025479710317,0.10052079562125252,33138412.88395842
2020-11-16T00:00:00Z,0.09982875688455334,0.10509347105778652,0.09904974565707925,0.10392818606702424,38092438.596709386
2020-11-17T00:00:00Z,0.10392448191102115,0.11249156065627103,0.10326385477778859,0.11057773640038855,69881770.90806274
 

Может ли кто-нибудь помочь мне структурировать эти данные в виде фрейма данных. Спасибо!

Ответ №1:

pandas.read_csv напрямую позволяет указать URL-адрес. Попробуй:

 df = pd.read_csv("https://data.messari.io/api/v1/assets/ada/metrics/price/time-series?interval=1damp;format=csv")