将字节响应转换为熊猫数据框

时间:2019-05-14 17:06:04

标签: python json dataframe python-requests

REST API调用响应(以字节为单位),如何将以字节为单位的数据转换为dataframe对象

url ='url_path with_ending_&format=csv'
response =requests.get(url, auth=(user,password), allow_redirects=True)
result = str((response.content, 'utf-8'))
data = StringIO(result)
df = pd.DataFrame(data)

1 个答案:

答案 0 :(得分:5)

我已经通过Pandas.read_csv()解决了相同的问题

result = str(response.content, 'utf-8')
data = StringIO(result)
df = pd.read_csv(data)