Search code examples
pythonpandasdataframeattributeerror

AttributeError: 'DataFrame' object has no attribute 'melt'


I'm using python 3.6 on Jupyter notebook. I'm trying to use pandas melt method on a simple 317x83 data frame called bshort. I'm using the following code for melting:

bmelt = bshort.melt(['artist','track','time','date.entered'],['wk1','wk2','wk3'],'week','rank')

but I keep running into an attribute error:

AttributeError: 'DataFrame' object has no attribute 'melt'

I upgraded pandas but it didn't solve my problem. Any suggestion on how to make it work?


Solution

  • Before pandas 0.20.0, melt was only a pandas method, not a DataFrame method. If you have an older pandas, use pd.melt(bshort,...) instead of bshort.melt(...).