Python DataFrame error for having a header with parenthesis
<p>I am very new to python and programming in general. I have a CSV file that has the first column as string headers.</p>

<p>ie</p>

<pre><code>time, speed(m/s), distance(m)
2,6,20
3,2,10

etc..
</code></pre>

<p>What I am trying to do is a program that will spit out a bunch of graphs based on my selection. for example time vs speed. or time vs speed and distance.</p>

<p>My first issue is whenever I try to graph something that has a parenthesis in its name for example:</p>

<pre><code>df.Accel_Y(g).plot(color='r',lw=1.3)
</code></pre>

<p>I receive an error of:</p>

<blockquote>
  <p>AttributeError: 'DataFrame' object has no attribute 'Accel_Y'</p>
</blockquote>

<p>It works fine if I try with a different column that has no parenthesis.</p>

<p>I tried to assign accel_y(g) to a letter for example z. Then doing this:</p>

<pre><code>f.z.plot(color='r',lw=1.3)
</code></pre>

<p>that also didn't work.</p>

<p>Here is my code:</p>

<pre><code>import pandas as pd
from pandas import DataFrame, read_csv
import numpy as np
import matplotlib.pyplot as plt


df = pd.DataFrame.from_csv('Flight102_Complete.csv')
df.KestrelTime.plot(color='g',lw=1.3)
df.Accel_Y(g).plot(color='r',lw=1.3)
print (df)
</code></pre>

<p>You should consider that accessing your columns via the <code>.</code> (dot) operator a privileged convenience.  It can break under many circumstances and sometimes silently so.  If you want to access the column do so with <code>[]</code> or <code>loc[]</code> or <code>iloc[]</code>.</p>

<p>Parenthesis are one of the conditions that will break the <code>.</code> accessor paradigm.</p>

<p>In your case<br>
Don't do</p>

<pre><code>df.Accel_Y(g).plot(color='r', lw=1.3)
</code></pre>

<p>Instead do</p>

<pre><code>df['Accel_Y(g)'].plot(color='r', lw=1.3)
</code></pre>

python pandas matplotlib dataframe