-1
df.rename(columns={'nan': 'RK', 'PP': 'PLAYER','SH':'TEAM','nan':'GP','nan':'G','nan':'A','nan':'PTS','nan':'+/-','nan':'PIM','nan':'PTS/G','nan':'SOG','nan':'PCT','nan':'GWG','nan':'PPG','nan':'PPA','nan':'SHG','nan':'SHA'}, inplace=True)     

This is my code to rename the columns according to http://www.espn.com/nhl/statistics/player/_/stat/points/sort/points/year/2015/seasontype/2

I want both the tables to have same column names. I am using python2 in spyder IDE.
When I run the code above, it gives me this error:

AttributeError: 'list' object has no attribute 'rename'
gre_gor
  • 6,669
  • 9
  • 47
  • 52

2 Answers2

1

The original question was posted a long time ago, but I just came across the same issue and found the solution here: pd.read_html() imports a list rather than a dataframe

When you do pd.read_html you are creating a list of dataframes since the website may have more than 1 table. Add one more line of code before you try your rename:

dfs = pd.read_html(url, header=0)

and then df = dfs[0] ; you will have the df variable as a dataframe , which will allow you to run the df.rename command you are trying to run in the original question.

Szymon Maszke
  • 22,747
  • 4
  • 43
  • 83
rherbst612
  • 11
  • 1
-2

this should be able to fix , df is you dataset df.columns=['a','b','c','d','e','f']