Sparkles
Sparkles

Reputation: 61

Convert bytes response to pandas dataframe

REST API call response in bytes, how to convert the data in bytes to dataframe object

import requests
import pandas as pd
from io import StringIO


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)

Upvotes: 1

Views: 6686

Answers (1)

metalrt
metalrt

Reputation: 366

I have solved the same issue with Pandas.read_csv();

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

Upvotes: 6

Related Questions