2

i have tried to string the column names and then change them - no succces, it left it NaN

data.rename(columns=str).rename(columns={'NaN':'Tip Analiza','NaN':'Limite' }, inplace=True)

i tried to use the in function to replace NaN- no succes - it gave an error,

TypeError: argument of type 'float' is not iterable

data.columns = pd.Series([np.nan if 'Unnamed:' in x else x for x in data.columns.values]).ffill().values.flatten()

what should i try ?

Shubham Sharma
  • 68,127
  • 6
  • 24
  • 53
SuperLiviu
  • 23
  • 3
  • Have you read this post? It should be pretty comprehensive. https://stackoverflow.com/questions/11346283/renaming-columns-in-pandas If you know the exact column names that you want for each column, you might just want to pass a list to `data.columns = ['Tip Analiza', 'Limite']` – Ji Wei Jun 22 '20 at 17:00
  • 3
    if you use dictionary `{'NaN':'Tip Analiza','NaN':'Limite' }` then this dictionary will be reduced to `{'NaN':'Limite' }` - you should rather assign directly all column names at once. BTW: do you get this error whit this code ? You could check first `data.rename(columns=str)` if this don't make problem. – furas Jun 22 '20 at 17:02

1 Answers1

0

Try:

data.columns=map(str, data)

# in case of unique column names
data=data.replace({"col1": "rnm1", "col2": "rnm2"})

# otherwise ignore first line, and just do
data.columns=["rnm1", "rnm2"]
Grzegorz Skibinski
  • 12,624
  • 2
  • 11
  • 34