[英]“TypeError: expected string or bytes-like object” while reading csv file in python with nltk
I'm doing pre-processing on this csv file but it didn't proceed - I got an error of "TypeError: expected string or bytes-like object"
: 我正在对这个csv文件进行预处理,但它没有继续 - 我得到一个错误
"TypeError: expected string or bytes-like object"
:
import pandas as pd
import numpy as np
import string
import nltk
dataset =pd.read_csv('blogtext.csv')
seq=dataset.iloc[:,6]
the output would be a 7 column ofblogtext.csv file but I'm getting an error. 输出将是7列的bloglog.csv文件,但我收到一个错误。
I guess you have float values in your dataset. 我猜你的数据集中有漂浮值。
You need to convert these float values to string values. 您需要将这些浮点值转换为字符串值。
The "pandas.DataFrame.iloc" is Purely integer-location based indexing for selection by position, .iloc[] is primarily integer position based (from 0 to length-1 of the axis), but may also be used with a boolean array. “pandas.DataFrame.iloc”是纯粹基于整数位置的索引,用于按位置选择,.iloc []主要是基于整数位置(从轴的0到长度-1),但也可以与布尔数组一起使用。
For example , 例如 ,
import pandas as pd
mydict = [{'a': 1, 'b': 2, 'c': 3, 'd': 4},
{'a': 100, 'b': 200, 'c': 300, 'd': 400},
{'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000 }]
df = pd.DataFrame(mydict)
print(df.iloc[0])
'''
Output:
a 1
b 2
c 3
d 4
'''
df.iloc[[0]]
'''
Output
a b c d
0 1 2 3 4
'''
df.iloc[[0, 1]]
'''
Output
a b c d
0 1 2 3 4
1 100 200 300 400
'''
df.iloc[:3]
'''
Output
a b c d
0 1 2 3 4
1 100 200 300 400
2 1000 2000 3000 4000
'''
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.