熊猫多个布尔滴

时间:2015-11-30 09:44:31

标签: python pandas

我一直在尝试逐行进行pandas DF的多次下降:

df_clean = df_merged[df_merged.GDP_current != '..']
df_clean = df_clean[df_clean.GDP_growth != '..']

在一条线上有更有效的方法吗?我尝试使用下面的代码,但它不起作用:

df_clean = df_merged['GDP_current' != '..'] | df_merged['GDP_growth' != '..'] | df_merged['GDP_per_capita' != '..']

OR

df_clean = df_merged.drop[df_merged['GDP_growth' == '..'] | df_merged['GDP_current' == '..'] | df_merged['GDP_per_capita' == '..']]

1 个答案:

答案 0 :(得分:0)

然后,由于运营商优先权,您需要将条件包装在括号中:

df_clean = df_merged[(df_merged['GDP_current' != '..']) | (df_merged['GDP_growth' != '..']) | (df_merged['GDP_per_capita' != '..'])]