Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 基于列值删除数据帧行_Python_Dataframe - Fatal编程技术网

Python 基于列值删除数据帧行

Python 基于列值删除数据帧行,python,dataframe,Python,Dataframe,我基于一个网站()创建了代码,用于根据列值删除数据框中的行。“区域类型”列可以有5个值之一(响应按钮文本、响应按钮图像、固定、时间限制屏幕或继续按钮)。除非该行的值为“response\u button\u image”,否则我希望从数据帧中删除该行 # select all of the rows that are not to do with the task i.e. fixation screens etc. indexZoneType = df[ (df['zone_type'] =

我基于一个网站()创建了代码,用于根据列值删除数据框中的行。“区域类型”列可以有5个值之一(响应按钮文本、响应按钮图像、固定、时间限制屏幕或继续按钮)。除非该行的值为“response\u button\u image”,否则我希望从数据帧中删除该行

# select all of the rows that are not to do with the task i.e. fixation screens etc.

indexZoneType = df[ (df['zone_type'] == 'fixation') & (df['zone_type'] == 'response_button_text') & (df['zone_type'] == 'timelimit_screen') & (df['zone_type'] == 'continue_button')].index

# delete these rows

df.drop(indexZoneType , inplace=True)

我觉得这个代码应该有用?我没有得到任何错误,但是当执行
print(df)
时,数据帧没有改变


谢谢。

好的,所以您的条件是相互排斥的,您可能想在那里使用“或”,即

indexZoneType=df[(df['zone_type']='fixement'))(df['zone_type']='response_button_text')(df['zone_type']='timelimit_screen')(df['zone_type']='continue_button')。索引
或者更好-使用
df.isin(…)
df.loc[…]

indexZoneType=df.loc[df['zone\u type'].isin(['fixture','response\u button\u text','timelimit\u screen','continue\u button'])。索引
或者更简单:

indexZoneType=df.index[df['zone\u type'].isin(['fixture'、'response\u button\u text'、'timelimit\u screen'、'continue\u button'])]
参考: