从python列表中过滤值

时间:2018-10-19 03:24:52

标签: python-3.x pandas

我有一个这样的列表L1=[] L2=[] def big_data(query,x,y): x = [] r = requests.get("http://bigdata.com/metrics/?" + query) r0 = r.json()[0][u'datapoints'] returned_data = r0[17:] for datapoint1 in returned_data: x.append(datetime.fromtimestamp(datapoint1[1]).strftime('%I%P').lstrip('0').upper()) y =[item[0] for item in returned_data] print(x) print(y) big_data(domain,L1,L2) print(L1) print(L2) When I am running above script I am able to getting a value for x and y but its not giving me anything for L1 and L2. I am not able to recall what basic thing I am missing here, Can someone please let me know what I am missing here. Output I am getting is something like this:- x = ['4PM', '5PM', '6PM', '7PM'] y = [291783, 3090123, 2736213, 105331] L1 = [] L2 = [] 我有一个列为“ file_name”的数据框 有没有办法使用python列表过滤行?

我知道

['1.jpg','222.jpg','333.jpg']

但这需要手动编码每个值,而不是使用for循环。

2 个答案:

答案 0 :(得分:2)

尝试: df_filtered = df[(df.file_name.isin([['1.jpg','222.jpg','333.jpg']])]

答案 1 :(得分:0)

这应该有效:

df_filtered = df[df['file_name'].isin(['1.jpg','222.jpg','333.jpg'])]