SAM244776
SAM244776

Reputation: 1465

Change column name with a .0 in Pandas

I have a dataframe with columns as Country, 2015.0,2016.0,2017.0 these are suppose to be years. But the column name has .0 in it. I tried to rename them but rename is not working. I am not able to remove the .0 at the end. Any suggestions.

Upvotes: 1

Views: 448

Answers (1)

piRSquared
piRSquared

Reputation: 294508

rename

def f(x):
    try:
        return int(float(x))
    except ValueError:
        return x

df.rename(columns=f)

Upvotes: 4

Related Questions