📜  从列中的数字中去除符号 - 无论代码示例

📅  最后修改于: 2022-03-11 15:00:23.041000             🧑  作者: Mango

代码示例1
row1list = ['$500 -', 'www']
row2list = ['$4.00 -', 'xyz']
df = pd.DataFrame([row1list, row2list],
                  columns=['Price', 'abc'])

# option 1:  regex capture groups
df['Price'] = df['Price'].str.replace('([0-9]+)', r'\1', regex=True).astype(float)

# option 2:  extract
df['Price'] = df['Price'].str.extract('([0-9.]+)').astype(float)

# print(df)
#    Price  abc
# 0  500.0  www
# 1    4.0  xyz