2024-10-01 11:24:15 发布
网友
如何使用split匹配列中转换为str的int
personid = '23' cond = (personid == x for x in df['wait'].str.split(",")) rows = df.loc[cond, :]
df['wait']包含类似“2,13,23”的str
df['wait']
当前它返回Empty DataFrame
Empty DataFrame
如果将expand=True添加到^{}获取数据帧,并通过拆分的值使用新列fileld,然后通过==by ^{}进行比较,并通过^{}测试每行是否至少有一个True。由^{}进行的最后筛选:
expand=True
==
True
#personid is string - `''` personid = '23' cond = df['wait'].str.split(",", expand=True).eq(personid).any(axis=1) rows = df[cond]
如果要匹配personid中的整数值:
personid
#personid is integer personid = 23 cond = df['wait'].str.split(",", expand=True).astype(float).eq(personid).any(axis=1) rows = df[cond]
您的解决方案应该更改:
cond = [any(y == personid for y in x) for x in df['wait'].str.split(",")]
如果将} 获取数据帧,并通过拆分的值使用新列fileld,然后通过} 进行比较,并通过^{} 测试每行是否至少有一个} 进行的最后筛选:
expand=True
添加到^{==
by ^{True
。由^{如果要匹配
personid
中的整数值:您的解决方案应该更改:
相关问题 更多 >
编程相关推荐