pandas 如何在Python中删除特定的变量名?

csga3l58  于 2023-06-20  发布在  Python
关注(0)|答案(2)|浏览(138)

数据如下:

id  date    age case_id country province    region  sex travel  travelh
1   1516    2020-03-23  40-49   1516    Canada  Ontario York    Male    1   Costa Rica
4   5658    2020-03-29  60-69   5657    Canada  Ontario Algoma  Female  1   United States
5   642 2020-03-18  Not Reported    642 Canada  Nova Scotia Not Reported    Not Reported    1   Not Reported
6   3560    2020-03-26  60-69   3560    Canada  Ontario Simcoe Muskoka  Male    1   India, United Arab Emirates
7   725 2020-03-18  80-89   725 Canada  Ontario Chatham-Kent    Female  1   United States

我写了

df.dropna(inplace=True)

但它并不适用于所有“未报告”。是否有任何方法可以删除数据集中的“未报告”行?

des4xlb0

des4xlb01#

您可以使用以下代码删除数据集中具有Not Reported值的行:

df = df[df != 'Not Reported'].dropna(how='any')
iklwldmw

iklwldmw2#

Not Reported转换为None

df = df.replace('Not Reported', None).dropna()

相关问题