我有一个示例数据框,我希望删除所有单词并保留值。
Column1 Column2 Column3 Column4 Column5
5FQ 1.047 S$55.3 UG44.2 as of 02/Jun/2016 S$8.2 mm
是否可以删除单词并保留所有数字? IE:获得以下所需结果:
Column1 Column2 Column3 Column4 Column5
5 1.047 55.3 44.2 8.2
请您参考如下方法:
一种方法是:
In [212]: df
Out[212]:
Column1 Column2 Column3 Column4 Column5
0 5FQ 1.047 S$55.3 UG44.2 as of 02/Jun/2016 S$8.2 mm
In [213]: df.apply(lambda x: x.astype(str).str.extract(r'(\d+\.?\d*)', expand=True).astype(np.float))
Out[213]:
Column1 Column2 Column3 Column4 Column5
0 5.0 1.047 55.3 44.2 8.2
