Reputation: 1
I am using Pandas to import a small csv file which seems to work out. When I look at the imported file i see all the data in a nice format with all the column headings and the corresponding data. My issue is when I try to run the command report.(tab key) for instance I only see a few column headings in that list. When I manually try to run report.RouterName I get an error. The column headings that I do not see are: RouterName, Router_Type, Switch_IP and CPU. If I run report.columns I see all of the column headings listed. What am I doing wrong?
In [1]: import pandas as pd
In [2]: report = pd.read_csv("/Users/iron-horse/Documents/Python_Files/Workbook1.csv")
In [3]: report
Out[3]:
RouterName Router_Type Switch_IP Software_Rev CPU \
0 BRPTCT0101 GX-550 10.10.50.7 09.01.01.20 NP
1 BRPTCT0106 CBX-500 (3 PS) 10.10.50.56 09.01.01.20 SP
2 BRPTCT0107 GX-550 10.10.50.35 09.01.01.20 NP
3 BRPTCT0102 CBX-500 (3 PS) 10.10.50.67 09.01.01.20 SP
Card_Fill Trunks LogicalPorts CircuitEndpoints Region Area
0 8 2 22 795 CT NE
1 13 6 74 905 CT NE
2 12 34 59 2039 CT NE
3 11 4 45 815 CT NE
In [4]: report.columns
Out[4]: Index([u'RouterName ', u'Router_Type ', u'Switch_IP ', u'Software_Rev', u'CPU ', u'Card_Fill', u'Trunks', u'LogicalPorts', u'CircuitEndpoints', u'Region', u'Area'], dtype='object')
In [5]: report.RouterName
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-a89b0f0e8073> in <module>()
----> 1 report.RouterName
/Users/iron-horse/anaconda/lib/python2.7/site-packages/pandas/core/generic.pyc in __getattr__(self, name)
1841 return self[name]
1842 raise AttributeError("'%s' object has no attribute '%s'" %
-> 1843 (type(self).__name__, name))
1844
1845 def __setattr__(self, name, value):
AttributeError: 'DataFrame' object has no attribute 'RouterName'
In [6]:
Upvotes: 0
Views: 1859
Reputation: 9946
it's spacing. look at the exact column name. what is it?
a fix would be to do something like:
df.columns = map(str.strip, df.columns)
and then you could access the column name like df.RouterName
if you want to do it as is, you have to do df['RouterName ']
Upvotes: 3