I have a CSV file which included some films info, and I want to remove column director
and cast
, but pandas told me KeyError.
Source Code:
import pandas as pd
if __name__ == '__main__':
df = pd.read_csv(r'titles.csv', sep='\t')
info = df.info
# print(df.head())
# print(df.tail())
# print('dftypes: ', df.dtypes)
# null = df.isnull().sum(axis=1)
#
# print(null)
# df2=df.drop(['director'],axis=1)
print(df.columns)
df.drop(labels='director', axis=1)
Columns in csv file:
show_id, type, title, director, cast, country, date_added, release_year, rating, duration, listed_in, description
Error info:
KeyError: "['director'] not found in axis"
I have tried to drop like the follows:
df.drop(labels=['director', 'cast'], axis=1)
# or
df.drop(columns=['director', 'cast'])