[英]How to remove rows with special character at the end of string in Python
I want to remove rows if the column 'Submitter'
has special character 'X'
at the end of the string in dataframe.如果'Submitter'
列在数据帧中的字符串末尾有特殊字符'X'
,我想删除行。
Submitter Age Country
AfiqX 23 Malaysia
Nur, AthirahX 23 Malaysia
Nur, Alia 23 Malaysia
In the above example dataframe, I want to delete rows 1 & 2 as it contains 'X' at the end of the name.在上面的示例数据框中,我想删除第 1 行和第 2 行,因为它在名称末尾包含“X”。
你可以使用str(pandas series)的endswith
df = df[~df['Submitter'].str.endswith('X')]
df = pd.DataFrame(data)
print(df[df['Submitter'].str.endswith("X") == False])
this will give all the rows which don't end with X这将给出所有不以 X 结尾的行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.