Since you did not provide your data as text, I have created an example dataframe:
Input:
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
Output:
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 series have built in string processing methods. You can use str.endswith(')') to filter your data. Notice that df['branch'].str.endswith(')')
will return a boolean mask.
Input:
df[df['branch'].str.endswith(')')]
Output:
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.