drop column python csv code example
Example 1: python code to drop columns from dataframe
new_df = df.drop(labels='column_name', axis=1)
df = df.drop(labels='column_name', axis=1)
df = df.drop(['list_of_column_names'], axis=1)
Example 2: delete a row in pandas dataframe
df.drop(df.index[2])
Example 3: pandas read_csv drop column
cols = list(pd.read_csv("sample_data.csv", nrows =1))
print(cols)
unused = ['col1', 'col2']
df= pd.read_csv("sample_data.csv", usecols =[i for i in cols if i not in unused])