[英]Python Pandas : how to add values in column group by a particular row and put the result in a new column
[英]How do I select a particular ROW in a single column CSV file containing a particular "substring" and add to a new list with python Pandas?
我有一个包含大量行的单列 CSV 文件。 如何提取包含特定“子字符串”的行,然后将该行添加到新列表中?
问候
帕巴特
也许这会让你走向解决方案......
输入列表(需要返回带有字母 a 和 t 的所有行('at')...
Col1
0 the
1 cat
2 sat
3 on
4 the
5 mat
6 for
7 a
8 very
9 long
10 time
11 at
12 Batman’s
13 house
代码...
my_substring = 'at'
df['Col2'] = df['Col1'].str.contains(my_substring, na=False)
df = df[df.Col2]
del df['Col2']
df
输出...
Col1
1 cat
2 sat
5 mat
11 at
12 Batman’s
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.