[英]Python Remove specific string in dataframe column
I have a df with a one specific column like this:我有一个带有这样一个特定列的 df:
var
100 asc
200 asc
150 asc
75 asc
I want to remove asc and retain as number so to get我想删除 asc 并保留为数字以便得到
var
100
200
150
75
Running跑步
number =df['var'].replace('\asc',regex=True) number =df['var'].replace('\asc',regex=True)
Yet nothing happens resulting df is exactly the same as the original one, yet no error are shown...然而什么也没发生,结果 df 与原来的完全相同,但没有显示错误......
Any ideas?有任何想法吗?
Let us try让我们试试
df['var'] = df['var'].str.strip(' asc')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.