我有以下文字column A:
A
hellothere_3.43
hellothere_3.9
我想extract仅另一个新列 B(A 旁边)的数字,例如:
B
3.43
3.9
I use: str.extract('(\d.\d\d)', expand=True)
但是这个copies只有 3.43(即确切的位数)。有没有办法让它更通用?
非常感谢!
使用正则表达式。
Ex:
import pandas as pd
df = pd.DataFrame({"A": ["hellothere_3.43", "hellothere_3.9"]})
df["B"] = df["A"].str.extract("(\d*\.?\d+)", expand=True)
print(df)
Output:
A B
0 hellothere_3.43 3.43
1 hellothere_3.9 3.9
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)