1

I am trying to get some data from mysportsfeeds.com and it returns me a csv file which is instantly converted to a 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 I convert res_table to a pandas dataFrame in the fastest way?

And it 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

1 Answer 1

2

It seems you need StringIO:

from pandas.compat import StringIO

df = pd.read_csv(StringIO(res_table))
Sign up to request clarification or add additional context in comments.

1 Comment

Glad can help you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.