Reading CSV column name starting with number (Python)
<p>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 <code>Teams.csv</code> has columns with names or headers such as <code>R</code>, <code>AB</code>, <code>H</code>, <code>2B</code>, <code>3B</code>, etc. Specifically, the CSV file is the Lahman's Baseball Database's <a href="http://www.seanlahman.com/baseball-archive/statistics/" rel="nofollow">Teams.csv file</a>.</p>

<p>Now when I read this file in Python, I use this:</p>

<pre><code>#imported pandas as pd
df = pd.read_csv("Teams.csv")

#Get stats for offense
R = df.R
AB = df.AB
H = df.H
</code></pre>

<p>and these work fine, but when I try to import <code>2B</code> and <code>3B</code> though</p>

<pre><code>doubles = df.2B
triples = df.3B
</code></pre>

<p>these give a syntax error because of Python not having variables start with digits.</p>

<p>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 <code>X2B</code> and <code>X3B</code>?</p>

<p>I rather not do the latter, because Lahman's Baseball Database has A LOT of CSV files.</p>