答案 0 :(得分:0)
由于您没有以文本形式提供数据,因此我创建了一个示例数据框:
输入:
d = {'college_name': ['College {}'.format(i+1) for i in range(8)], 'branch': ['Civil Enigineering '+ '(4 Years)'*(i%2) for i in range(8)]}
df = pd.DataFrame(data=d, columns=['college_name','branch'])
df
输出:
college_name branch
0 College 1 Civil Enigineering
1 College 2 Civil Enigineering (4 Years)
2 College 3 Civil Enigineering
3 College 4 Civil Enigineering (4 Years)
4 College 5 Civil Enigineering
5 College 6 Civil Enigineering (4 Years)
6 College 7 Civil Enigineering
7 College 8 Civil Enigineering (4 Years)
Pandas系列具有内置的字符串处理方法。您可以使用str.endswith(')')过滤数据。请注意,df['branch'].str.endswith(')')
将返回一个布尔掩码。
输入:
df[df['branch'].str.endswith(')')]
输出:
college_name branch
1 College 2 Civil Enigineering (4 Years)
3 College 4 Civil Enigineering (4 Years)
5 College 6 Civil Enigineering (4 Years)
7 College 8 Civil Enigineering (4 Years)