【发布时间】:2021-09-08 16:36:43
【问题描述】:
我有下面的熊猫数据框
col1 col2 col3
1 2 new york
0 5 virginia
1 2 YK
..............
我有喜欢的城市列表
L1 = ['new york', 'virginia']
L2 = ['virginia','YK']
L3 = ['YK', 'new york']
L4 = ['new york', 'YK']
我想在 pandas 数据框 col3 中搜索城市。以便它以与列表中相同的顺序匹配连续行。在这里,我的列表 L1 和 L2 应该只匹配,因为 L1 和 L2 的所有元素在列中以严格相同的顺序出现而不会跳过。
I searhed a lot and find rolling windows, shift etc. but could not get through.
【问题讨论】:
-
为什么
L2和L3不匹配?你如何存储这些列表?那里有多少?它是列表列表吗?...抱歉,如果我遗漏了什么。 -
这不是一个大问题,唯一的问题是我想确保一组城市在 pandas 数据框中有序
-
是的,
["virginia", "YK"]也在框架中,对吗?第二和第三行 -
是的,抱歉,我正在编辑我的问题
-
["new york", "YK"]被认为是匹配还是需要严格按连续顺序排列?
标签: python pandas dataframe rolling-computation