Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export to CSV #301

Open
jmartin1344 opened this issue Aug 9, 2018 · 1 comment
Open

Export to CSV #301

jmartin1344 opened this issue Aug 9, 2018 · 1 comment

Comments

@jmartin1344
Copy link

jmartin1344 commented Aug 9, 2018

I'd like to export all data from a given nfldb query into a CSV file so i can load in Tableau Public - I remember this was possible in nflgame I think.

Could anyone provide an example of how to do this? I'm fairly basic at this stuff.

Appreciate it.

@MargareeMan
Copy link

MargareeMan commented Oct 18, 2018

For starters see 'https://github.com/derek-adair/nflgame/wiki/Tutorial-for-non-programmers:-Installation-and-examples' , the section: "I don't care about Python. Can I use Excel please?". Also, look at the original nfldb Wiki 'https://github.com/BurntSushi/nfldb/wiki' . Your question, I think is really a Python or SQL question. The examples should get you started.

I dug up a piece of code I wrote a couple of years ago (and for this example changed the year in the query). I am not a programmer and I do not use Python (except by example). I don't even remember where I got this code from (so I apologize to anyone I am copying from without reference).

import nflgame
import nflgame.sched
import csv

schedule_games = nflgame.sched.games

with open("E:\NFLDB 2018 incarnate\\2018 Schedule.csv", 'wb') as csvfile:
    schedulewriter = csv.writer(csvfile, delimiter=',')
    schedulewriter.writerow(['Key','Home', 'Away', 'Week', 'Year'])
    for key in schedule_games:
        game = schedule_games[key]
        if game['year'] == 2018 and game['season_type'] == 'REG':
            schedulewriter.writerow([game['eid'], game['home'], game['away'], game['week'], game['year']])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants