英文:
Remove special character \r carriage return from column headers
问题
如何删除csv文件标题中的特殊字符?
Col1\r -> 列名
在 Col1\r
中,我们基本上会将其视为 Col1
,在Excel中打开时实际上是看不到的。
我已将数据移动到一个名为 df
的数据框中。
# 从列标题中删除特殊字符
dfcolumns = df.columns
英文:
How do we remove special characters in the header of a csv file?
Col1\r -> Column name
In Col1\r
we would basically see it as Col1
, which is actually not visible when opened in Excel.
I have moved the data to a dataframe df
.
# Remove special characters from column headers
dfcolumns = df.columns
答案1
得分: 1
你可以尝试类似这样的操作:
df.columns = df.columns.str.replace('\r', '')
更多信息请参考此处。
英文:
You can try something like this:
df.columns = df.columns.str.replace('\r', '')
More information here.
答案2
得分: 0
Depends on where are you taking the column name from. If it's a json you need to open it with the proper encoding. If you have this string handled by another variable in plain text, you need to manipulate it and clean the bad values. with
string_variable.replace('\r', '')
英文:
Depends on where are you taking the column name from. If it's a json you need to open it with the propper encoding. If you have this string handled by another varaiable in plain text, you need to manipulate it and clean the bad values. with
string_variable.replace('\r', '')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论