如何删除那些列表中的列元素的行?
How to drop rows for those column elements which are list?
在上图中,最后一列 ('Location') 是一个列表。在以下情况下,我需要删除这些行:
if first item in the list 'location' is greater than 60.0, those rows are not needed for me
如果我使用:
for i in range(len(output)):
trip_df = output.drop(output[ output['location'][i][0] > 60].index)
错误是:关键字错误:真
我不能简单地把 output['location'][0] 因为它只表示第一行,我怎么能用或不用 for循环?
P.S :对不起,我不知道如何将值放入 table
使用str
方法获取第一项:
df = pd.DataFrame({"Location":[[61,50],[117,24],[3,5]], #dummy data
"Values":[2,4,6]})
print (df[~df["Location"].str[0].gt(60)])
Location Values
2 [3, 5] 6
在上图中,最后一列 ('Location') 是一个列表。在以下情况下,我需要删除这些行:
if first item in the list 'location' is greater than 60.0, those rows are not needed for me
如果我使用:
for i in range(len(output)):
trip_df = output.drop(output[ output['location'][i][0] > 60].index)
错误是:关键字错误:真
我不能简单地把 output['location'][0] 因为它只表示第一行,我怎么能用或不用 for循环?
P.S :对不起,我不知道如何将值放入 table
使用str
方法获取第一项:
df = pd.DataFrame({"Location":[[61,50],[117,24],[3,5]], #dummy data
"Values":[2,4,6]})
print (df[~df["Location"].str[0].gt(60)])
Location Values
2 [3, 5] 6