![](/img/trans.png)
[英]How to not print out Quote characters when creating a CSV file in Python
[英]How to remove quote characters around array when loading a csv in Python?
我无法删除数组周围出现的引号字符。 当我像这样读入我的文件时:
data = pd.read_csv('filepath.csv', sep='|', index_col=0, nrows=5)
我有问题的列的 dtype 是object
但各个条目是字符串:
print(type(data.body_tokens[0]))
data.body_tokens[0]
<class 'str'>
"['he', 'knows', 'what', 'he', 's', 'doing']"
如何删除数组周围的引号?
import ast
string = "['he', 'knows', 'what', 'he', 's', 'doing']"
list = ast.literal_eval(string)
type(list) #list
print(list) #['he', 'knows', 'what', 'he', 's', 'doing']
想要这个吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.