I had a question about reading in a column name from a CSV file into my python program starting with a number? So my CSV datafile called
has columns with names or headers such as
, etc. Specifically, the CSV file is the Lahman's Baseball Database's Teams.csv file
Now when I read this file in Python, I use this:
#imported pandas as pd
df = pd.read_csv("Teams.csv")
#Get stats for offense
R = df.R
AB = df.AB
H = df.H
and these work fine, but when I try to import
doubles = df.2B
triples = df.3B
these give a syntax error because of Python not having variables start with digits.
Is there a way around this that I can do within Python itself? Or do I have to go into the CSV and rename the headers to lets say
I rather not do the latter, because Lahman's Baseball Database has A LOT of CSV files.