创建一个循环startswith特定的字符串pandas
我仍然是Python的初学者。我只想从df:
“ nofollow noreferrer”>的“ https://i.sstatic.net/gzuid.png”中,仅从特定前缀开始。
我正在尝试创建一个循环,请参见
names_list = []
for name in df['short_desc']:
if 'Specifc Group' in df['group']:
if name.startswith("Wrong Data"):
names_list.append(name)
下文t提取我想拥有的东西。我不确定出了什么问题。你能帮忙吗?
I'm still a python beginner. I would like to extract only records starts with specific prefix like 'Wrong Data' for 'Specific Group' from df:
I'm trying to create a loop, please see below:
names_list = []
for name in df['short_desc']:
if 'Specifc Group' in df['group']:
if name.startswith("Wrong Data"):
names_list.append(name)
But this loop doesn't extract what I would like to have. I'm not sure what went wrong. Could you please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于熊猫的很酷的事情是,您不必在循环中做这些事情。
或者,一行:
这是Pandas的“魔术索引”。这些比较操作员返回一系列布尔值,在情况为真的地方。将其传递到
df [...]
时,仅返回数组元素为true的行。The cool thing about pandas is that you don't have to do these things in a loop.
Or, in a single line:
This is pandas' "magic indexing". Those comparison operators return an array of booleans, True where the condition is true. When passing that to
df[...]
, that returns only the rows where the array element is True.您需要使用
.str.startswith
查找列以特定值开头的行:You need to use
.str.startswith
to find rows where a column starts with a particular value: