Sample values in the column ₡ $ L C$ Q
当我尝试访问pandas数据框中的此列时,将引发以下错误
UnicodeEncodeError:'charmap'编解码器无法在位置25编码字符'\ u20a1':字符映射到
答案 0 :(得分:0)
如果您的Excel工作表格式为
货币,一些数字
$,45
%,76
您可以将其下载为CSV,然后执行
df = pd.read_csv("filename.txt")
然后
currency_symbols = df.drop("currency",axis = 1)
然后,您的DF将是不包含货币符号的数据框,并且您将拥有一个以currency_symbols包含所有货币符号的数组
相反,如果您的文件看起来像
$ 45
%109 ...
在货币后跟您要提取的数字,您可以执行以下操作:
currency_symbols = ["$","%"]
df = pd.read_csv("yourfile.csv")
currencies = []
values = []
for elem in df["currency"].values:
string = elem
for e in currency_symbols:
if e in elem:
currencies.append(e)
string = string.replace(e,"")
values.append(string)
然后,您将获得两个数组:
货币= [“ $”,“%”]
和
values = [“ 45”,“ 109”]