Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 477373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:35:03+00:00 2026-05-13T00:35:03+00:00

I am trying to use examples that are fun/interesting to me in order to

  • 0

I am trying to use examples that are fun/interesting to me in order to learn MySQL and Python. I am new to both, as I am a finance guy by trade. I have learned quite a bit along the way, but I am at a point where I am not sure where to go.

The data files I am looking to import are contained in a zip file, hosted: here

I extracted the directory, are there are well over 1000 files. In the code below, I am simply trying to reference one of the files individually to parse it into MySQL.

I am fully aware that there has to be an easier way to go about this, but I am learning, and I am sure my code reflects it (you can see that I typed in some basic prints to see that my code was correct).

Any help you can provide will be GREATLY appreciated. Essentially, when it comes to Python, I am looking as it as a hobby and a way to get at the large amount of data on the web that I want to play with. I pasted my code below so you can see where I am coming from.

  • Brock

P.S. Sorry about the code below, can’t figure out a better way to post it.

The code below is my create table script

> DROP TABLE IF EXISTS `nba`.`event`;
CREATE TABLE  `nba`.`event` (
  `a1` varchar(45) DEFAULT NULL,
  `a2` varchar(45) DEFAULT NULL,
  `a3` varchar(45) DEFAULT NULL,
  `a4` varchar(45) DEFAULT NULL,
  `a5` varchar(45) DEFAULT NULL,
  `h1` varchar(45) DEFAULT NULL,
  `h2` varchar(45) DEFAULT NULL,
  `h3` varchar(45) DEFAULT NULL,
  `h4` varchar(45) DEFAULT NULL,
  `h5` varchar(45) DEFAULT NULL,
  `period` int(11) DEFAULT NULL,
  `time` time DEFAULT NULL,
  `team` varchar(3) DEFAULT NULL,
  `etype` varchar(15) DEFAULT NULL,
  `assist` varchar(45) DEFAULT NULL,
  `away` varchar(45) DEFAULT NULL,
  `block` varchar(45) DEFAULT NULL,
  `entered` varchar(45) DEFAULT NULL,
  `home` varchar(45) DEFAULT NULL,
  `left` varchar(45) DEFAULT NULL,
  `num` int(11) DEFAULT NULL,
  `opponent` varchar(45) DEFAULT NULL,
  `outof` varchar(45) DEFAULT NULL,
  `player` varchar(45) DEFAULT NULL,
  `points` int(11) DEFAULT NULL,
  `possession` varchar(45) DEFAULT NULL,
  `reason` varchar(50) DEFAULT NULL,
  `result` varchar(10) DEFAULT NULL,
  `steal` varchar(45) DEFAULT NULL,
  `type` varchar(30) DEFAULT NULL,
  `x` varchar(2) DEFAULT NULL,
  `y` varchar(2) DEFAULT NULL,
  `gameid` varchar(15) NOT NULL,
  `seqnum` int(11) NOT NULL AUTO_INCREMENT,
  `updated` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`seqnum`,`gameid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Datafiles of play by play from basketballgeek.com';

Here is my python script. I put the table above in a schema called NBA. I set my table up so that, I believe, a sequence number is created for every record entered into the db. I pass it the gameid as a string, and also assume that the timestamp will be created for every insert statement. I know there is an error, but I can’t figure out what it is.

sql = """LOAD DATA INFILE '%s' INTO TABLE event FIELDS TERMINATED BY ',' LINES TERMINATED BY '\\n';"""  % path

print sql

try:
    cursor.execute(sql)
    db.commit()
except:
    print "ERROR"
    db.rollback()

 db.close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:35:04+00:00Added an answer on May 13, 2026 at 12:35 am

    Why not use MySQLs own CSV import functionality?

    http://dev.mysql.com/doc/refman/5.0/en/load-data.html

    LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
      FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
      LINES TERMINATED BY '\n';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use PyLucene, and I can't find any code examples that actually
I'm using opengl and trying to create a first person camera. All examples use
I am trying to understand how to use reference parameters. There are several examples
I'm trying to use the new(ish) AS3 global error handling class. I am trying
Disclaimer: I am fairly new to using json. I am trying to use php
I am trying to learn pyparsing. It sounds promising and something that would be
I'm new to Php and am trying to replicate classes I use in c#
For just some fun i am trying to use Flat File databases to read
Trying to use the following demo example, using the 80px x 80px snap to
I am trying to use session data on multiple subdomains: www.example.com my.example.com test.example.com whateversub.example.com

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.