1

I have a list of columns that all have the same name and was wondering how I give each one a distinct title.

df= pd.read_excel('SEO Data 01.15.19.xlsx','Data Dump')
df.columns = df.iloc[0]
df=df.drop(df.index[0])
df.rename(columns={ df.columns[1]: ".1" })
d={'Clicks': ['Clicks1', 'Clicks2', 'Clicks3']}
df.rename(columns=lambda c: d[c].pop(0) if c in d.keys() else c)

I wanted a new table with the new headers but instead I end up with IndexError: pop from empty list

Pfwangs
  • 41
  • 5
  • I think is best if you add a sample input, `df.head(5)` for example or something like that. Also how many columns have the name `'Clicks'`? – Dani Mesejo Jan 23 '19 at 23:08

0 Answers0