简体   繁体   中英

Extract a substring in a column which is delimited by two specific characters in Pandas

我有一个数据框,其中包含一列“工资”,我想提取数字,因为此列包含这样的格式:“€123K”,所以我只想保留两个字符K之间的数字字符串,以便我得到一个只有数字的新列“ Wage2”。

I think need extract and if all values are integers is possible convert by astype :

df = pd.DataFrame({'Wage':['€123K', '€723K']})

df['Wage2'] = df['Wage'].str.extract('€(.*?)K', expand=False).astype(int)
print (df)
    Wage  Wage2
0  €123K    123
1  €723K    723

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM