我有一个示例数据框,希望删除所有单词并保留值。
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句