Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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 带有拆分字符串的dataframe.loc_Python_Python 3.x_Pandas_Dataframe - Fatal编程技术网

Python 带有拆分字符串的dataframe.loc

Python 带有拆分字符串的dataframe.loc,python,python-3.x,pandas,dataframe,Python,Python 3.x,Pandas,Dataframe,如何使用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 当前,如果addexpand=True通过拆分的值获取具有新列fileld的数据帧,则返回空数据帧,然后通过进行比较,并通过测试每行是否至少有一个True。最后筛选人: 如果要匹配

如何使用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


当前,如果add
expand=True
通过拆分的值获取具有新列fileld的数据帧,则返回
空数据帧

,然后通过进行比较,并通过测试每行是否至少有一个
True
。最后筛选人:

如果要匹配
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(",")]

如果add
expand=True
以通过拆分的值获取具有新列fileld的数据帧,则按进行比较,并测试每行是否至少有一个
True
。最后筛选人:

如果要匹配
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(",")]

请使用预期输出发布样本输入数据。请使用预期输出发布样本输入数据。此操作有效。你能解释一下语法吗?匹配的整数不会使用
int
而不是
float
?这很有效。你能解释一下语法吗?匹配的整数不是使用
int
而不是
float