Python 从数据帧中删除元素(错误项不存在)
我正在使用Python 从数据帧中删除元素(错误项不存在),python,pandas,numpy,jupyter-notebook,data-visualization,Python,Pandas,Numpy,Jupyter Notebook,Data Visualization,我正在使用df=df.drop(index='historicalbook')删除包含historicalbook的所有行 第一行是标题 id name book subject amount 1 name1 historical book 6 2 name2 lite
df=df.drop(index='historicalbook')
删除包含historicalbook
的所有行
第一行是标题
id name book subject amount
1 name1 historical book 6
2 name2 literature book 9
3 name3 historical book 4
我得到一个错误,在axis中找不到它。你知道为什么吗
谢谢大家! 只要这样做:
print(df[~df['subject'].str.contains('historical book')])
id name book subject amount
1 2 name2 literature book 9
用法:df[df['subject']!='historicalbook']