I think the column name that contains "Number"
is something like " Number"
or "Number "
. I'm assuming you might have a residual space in the column name. Please run print "<{}>".format(data.columns[1])
and see what you get. If it's something like < Number>
, it can be fixed with:
data.columns = data.columns.str.strip()
See pandas.Series.str.strip
In general, AttributeError: 'DataFrame' object has no attribute '...'
, where ...
is some column name, is caused because .
notation has been used to reference a nonexistent column name or pandas method.
pandas methods are accessed with a .
. pandas columns can also be accessed with a .
(e.g. data.col
) or with brackets (e.g. ['col']
or [['col1', 'col2']]
).
data.columns = data.columns.str.strip()
is a fast way to quickly remove leading and trailing spaces from all column names. Otherwise verify the column or attribute is correctly spelled.