简体   繁体   English

Python 删除 dataframe 列中的特定字符串

[英]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.

相关问题 正则表达式删除列数据框中字符串的特定部分python - Regex to remove specific parts of a string in a column dataframe python 从Python的Dataframe列中的String中删除子目录 - Remove subdirectories from String in Dataframe Column in Python python替换特定数据框列中的字符串 - python replace string in a specific dataframe column 从 Python 中的 dataframe 列中的特定字符串拆分 - Splitting at specific string from a dataframe column in Python Python pandas dataframe:在数组列中,如果第一项包含特定字符串,则从数组中删除该项 - Python pandas dataframe : In an array column, if first item contains specific string then remove that item from array 如何删除 Python 字符串列表的特定列? - How to remove specific column of Python string list? Pandas 数据框列删除第一个特定字符之前的字符串 - Pandas dataframe column remove string before the first specific character Python:从 dataframe 列值中删除特定字符 - Python: Remove specific character from dataframe column value Python:在数据框中用相同的值填充特定列并删除无用的行 - Python : Fill a specific column with the same value in a Dataframe and remove the rows useless 如何在 Python 中删除字符串/数据帧 [i] 的非特定字符 - How to remove non-specific char of a string/dataframe[i] in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM