Comment ajouter des en-têtes de colonne en pandas
#suppose team is a df that has unnamed columns (0,1...)
team.columns =['Name', 'Code', 'Age', 'Weight']
Captainspockears
#suppose team is a df that has unnamed columns (0,1...)
team.columns =['Name', 'Code', 'Age', 'Weight']
# python 3.x
import pandas as pd
import numpy as np
df = pd.DataFrame(data=np.random.randint(0, 10, (6,4)))
df.columns=["a", "b", "c", "d"]
print(df)
df_new = df.rename(columns={'A': 'a'}, index={'ONE': 'one'})
print(df_new)
# a B C
# one 11 12 13
# TWO 21 22 23
# THREE 31 32 33
print(df)
# A B C
# ONE 11 12 13
# TWO 21 22 23
# THREE 31 32 33
# adding column name to the respective columns
df.columns =['Name', 'Code', 'Age', 'Weight']
# displaying the DataFrame
print(df)
df = pd.DataFrame(d) #Uses default method for columns
print(df)