Search code examples
pythonpandasdataframecastingattributeerror

Using Pandas: function matches column name, unable to perform function


I was given a table by a client named with a column named "rank",
and I'm trying to convert the values in that column to an int type, but when I try to run the df.rank.astype(int) function on the column it thinks I'm trying to run the .astype() function on the .rank() function. Any way to prevent this?

df.rank.astype()
AttributeError: 'function' object has no attribute 'astype'

Solution

  • You can set declare the column using []

    df['rank'] = df['rank'].astpye()