Search code examples
pythonlogarithm

A simple log of a dataframe in python : Error : 'type' object does not support item assignment


I am trying to take a log of a dataframe and copy it into a new dataframe in Python and I get this error : 'type' object does not support item assignment

import math
y = pd.DataFrame
y['Number'] = np.log(df.Number)
y

Solution

  • Right now you're setting y to the DataFrame class, not an instance of it. You need to call the constructor to create a new dataframe:

    y = pd.DataFrame()
    

    then your assignment should work