字符串到数据框架PySpark/Python

mwecs4sa  于 2023-05-05  发布在  Python
关注(0)|答案(1)|浏览(150)

我试图将API的返回从text(string)转换为dataframe,但不幸的是我不能,有没有办法做到这一点。
从API返回的文本带有标题。

import requests

url = "test"

headers = {
    "accept": "text/csv",
    "authorization": "Bearer test"
}

response = requests.get(url, headers=headers, timeout=60)

print(response.text)

API输出
Device Type,OS Version,App Version,SDK Version,App ID,App Name,Bundle ID,Is Retargeting,Retargeting Conversion Type,Attribution Lookback,Reengagement Window,Is Primary Attribution,User Agent,HTTP Referrer,Original URL ,,2021-01-13 15:53:23,2023-01-01 01:32:37,uninstall,,,,,SDK,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,SA,BR,PE

wh6knrhe

wh6knrhe1#

我想你在找这个

import pandas as pd
from io import StringIO
import requests

url = "test"

headers = {
    "accept": "text/csv",
    "authorization": "Bearer test"
}

response = requests.get(url, headers=headers, timeout=60)

df = pd.read_csv(StringIO(response.text), header=None)
print(df)

相关问题