Home > Blockchain >  how can i replace the text/title of a column on dataset?
how can i replace the text/title of a column on dataset?

Time:12-22

dataset_poste.to_csv("dataset_poste_data.csv") dataset_poste = pd.DataFrame(dataset_poste)

dataset_poste = dataset_poste.drop(["Open", "High", "Low", "Adj Close", "Volume"], axis=1) dataset_poste = dataset_poste.replace("Close" , "Poste_close") dataset_poste.tail()

the code doesn't work for me, no error, but it doesn't change the title of my column

i don't really how to do it, please, help me

CodePudding user response:

If understand the question correctly, you are trying to rename one column in the dataframe, you can do it as follows:

df.rename(columns={"Close": "Poste_close"}, inplace=True)

CodePudding user response:

If I understand, if your dataframe have only one column

You can do this:

dataset_poste.columns = ['Poste_close']

And if you have other columns to rename:

dataset_poste.columns = ['Poste_close', 'Adj Close', 'Volume']

Remember: Always in dataframe column order

  • Related