![](/img/trans.png)
[英]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.