python - Supprimer une colonne d'un Pandas DataFrame

Mots clés : pythonpandasdataframepython

meilleur 4 Réponses python - Supprimer une colonne d'un Pandas DataFrame

vote vote

94

df = df.drop('column_name', 1) 
df.drop('column_name', axis=1, inplace=True) 
df = df.drop(df.columns[[0, 1, 3]], axis=1)  # df.columns is zero-based pd.Index 
df.drop(['column_nameA', 'column_nameB'], axis=1, inplace=True) 
df = df.drop(columns=['column_nameA', 'column_nameB']) 
vote vote

80

del df['column_name'] 
vote vote

72

columns = ['Col1', 'Col2', ...] df.drop(columns, inplace=True, axis=1) 
df = df.drop(columns, axis=1) 
vote vote

70

df.drop(df.columns[[0,1,3]], axis=1, inplace=True) 
df.drop(df.columns[[0]], axis=1, inplace=True) 
df.pop('column-name') 
df = DataFrame.from_items([('A', [1, 2, 3]), ('B', [4, 5, 6]), ('C', [7,8, 9])], orient='index', columns=['one', 'two', 'three']) 
   one  two  three A    1    2      3 B    4    5      6 C    7    8      9 
   two  three A    2      3 B    5      6 C    8      9 
   two A    2 B    5 C    8 

Questions similaires