我有一个带有包含货币符号的列的DataFrame,我正在寻找一种去除这些符号的有效方法,以便可以将列的数据类型转换为浮点型。
数据框:
Date Money(ILS)
0 2020-05-02 ₪77,000.00
1 2020-04-30 ₪80,600.00
2 2020-07-29 ₪86,600.00
3 2020-10-27 ₪113,963.00
4 2021-01-25 ₪134,963.00
5 2021-04-25 ₪155,963.00
6 2021-07-24 ₪176,963.00
7 2021-10-22 ₪197,963.00
8 2022-01-20 ₪218,963.00
9 2022-04-20 ₪239,963.00
10 2022-07-19 ₪260,963.00
我正在尝试从货币栏中去除₪符号。
我的功能:
@classmethod
def strip_symbols(cls):
cls.df = cls.df.apply(lambda x: x.str.strip('₪') if x.dtype == TypesConsts.OBJECT else x)
return cls.df
使用这种方法,我得到以下错误:
AttributeError: Can only use .str accessor with string values!
Use
DataFrame.select_dtypes
for get columns only of object dtype: