按条件删除熊猫数据框中的行

时间:2019-04-22 18:20:57

标签: python pandas dataframe

我有一个带有州和县的大熊猫数据框,但有些县只是整个州。我正在尝试逐行迭代以删除df ['STNAME'] == df ['COUNTY']的行。

    SUMLEV  REGION  DIVISION    STATE   COUNTY  STNAME  CTYNAME CENSUS2010POP   ESTIMATESBASE2010   POPESTIMATE2010 ... RDOMESTICMIG2011    RDOMESTICMIG2012    RDOMESTICMIG2013    RDOMESTICMIG2014    RDOMESTICMIG2015    RNETMIG2011 RNETMIG2012 RNETMIG2013 RNETMIG2014 RNETMIG2015
0   40  3   6   1   0   Alabama Alabama 4779736 4780127 4785161 ... 0.002295    -0.193196   0.381066    0.582002    -0.467369   1.030015    0.826644    1.383282    1.724718    0.712594
1   50  3   6   1   1   Alabama Autauga County  54571   54571   54660   ... 7.242091    -2.915927   -3.012349   2.265971    -2.530799   7.606016    -2.626146   -2.722002   2.592270    -2.187333
2   50  3   6   1   3   Alabama Baldwin County  182265  182265  183193  ... 14.832960   17.647293   21.845705   19.243287   17.197872   15.844176   18.559627   22.727626   20.317142   18.293499

我尝试了一个带循环的for循环,但没有给我输出。

for rows in df.iterrows():
     if ['STNAME'] == ['CTYNAME']:
          df.drop(axis=0)
          print(census_df)

再次,我要遍历行并删除df中的行。['STNAME'] == df ['COUNTY']。

0 个答案:

没有答案