我有以下输入数据帧。所有类型都是字符串。我想将它们转换为浮动。有各种各样的字符,但理想情况下,我希望只保留小数分隔符和数字。删除其他所有内容的最好方法是什么?我试过了:
corp = corp.replace(r'\$', '', regex=True).apply(pd.to_numeric)请问有没有替代all expect numeric AND comma的方法?
JPY JPY JPY JPY JPY JPY JPY JPY JPY JPY ... JPY JPY JPY JPY JPY JPY JPY JPY JPY JPY
Update time ...
2018/8/13 10:15 $34,424,234.98 this is a str ¥375,567,698 ¥304,734 ¥3,848,230,263 ¥101,677,219 0 ¥14,377,274 ¥47,719,464 ¥1,833 ... 0 0 0 0 0 0 0 0 0 0
2018/8/14 10:30 $34,424,234.98 ¥4,079,039,244 ¥375,567,698 ¥304,734 ¥3,131,351,753 ¥101,677,219 0 ¥14,377,274 ¥47,719,464 ¥1,833 ... 0 0 0 0 0 0 0 0 0 0
2018/8/15 10:30 $34,424,234.98 ¥4,644,436,742 ¥375,567,698 ¥304,734 ¥3,018,288,133 ¥101,677,219 0 ¥14,376,734 ¥48,551,464 ¥1,833 ... 0 0 0 0 0 0 0 0 0 0编辑:
这是一个解决方案..。
corp = corp.replace(r'[a-zA-Z]|¥|,', '', regex=True)发布于 2020-08-30 21:34:33
您可以使用
corp = corp.replace(r'[^\d.]+', '', regex=True).apply(pd.to_numeric)这样,您将删除除数字和点之外的所有字符。请参阅regex demo。
详细信息
[^ -一个被取反的字符类开始\d - digit. - dot]+ -取反的字符类end,一次或多次出现https://stackoverflow.com/questions/63653504
复制相似问题