cant change column name from 'NaN' to smth else

Viewed 79

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 ?

1 Answers

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"]
Related