python - Convert parsed csv file read as a string automatically to pandas data frame -
i trying data mysportsfeeds.com , returns me csv file instantly converted string in python.
import requests import base64 username = 'xxxx' password = 'xxxx' def send_request(request): # request try: response = requests.get( url=request, params={ "fordate": "20170401" }, headers={ "authorization": "basic " + base64.b64encode(username + ":" + password) } ) return response.content except requests.exceptions.requestexception: print('http request failed') res_table = send_request('https://www.mysportsfeeds.com/api/feed/pull/nba/2016-2017-regular/daily_game_schedule.csv?fordate=20170407') how can convert res_table pandas dataframe in fastest way?
and looks like:
#date/time of update: (none),#game id,#game date,#game time,#unplayed,#in progress,#completed,#current quarter,#current quarter seconds remaining,#current intermission,#away team id,#away team abbr.,#away team city,#away team name,#home team id,#home team abbr.,#home team city,#home team name,#location,#away score,#home score ,35119,2017-04-07,7:30pm,true,false,false,,,,91,atl,atlanta,hawks,86,cle,cleveland,cavaliers,quicken loans arena ,35120,2017-04-07,7:30pm,true,false,false,,,,92,mia,miami,heat,81,tor,toronto,raptors,air canada centre ,35121,2017-04-07,8:00pm,true,false,false,,,,83,nyk,new york,knicks,107,mem,memphis,grizzlies,fedex forum ,35122,2017-04-07,8:00pm,true,false,false,,,,88,det,detroit,pistons,109,hou,houston,rockets,toyota center ,35123,2017-04-07,8:30pm,true,false,false,,,,106,sas,san antonio,spurs,108,dal,dallas,mavericks,american airlines center ,35124,2017-04-07,9:00pm,true,false,false,,,,110,nop,new orleans,pelicans,99,den,denver,nuggets,pepsi center ,35125,2017-04-07,9:00pm,true,false,false,,,,100,min,minnesota,timberwolves,98,uta,utah,jazz,vivint smart home arena ,35126,2017-04-07,10:00pm,true,false,false,,,,96,okl,oklahoma city,thunder,104,phx,phoenix,suns,talking stick resort arena ,35127,2017-04-07,10:30pm,true,false,false,,,,103,sac,sacramento,kings,105,lal,los angeles,lakers,staples center
it seems need stringio:
from pandas.compat import stringio df = pd.read_csv(stringio(res_table))
Comments
Post a Comment