简体   繁体   English

使用nltk在python中读取csv文件时出现“TypeError:期望的字符串或类字节对象”

[英]“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.

相关问题 类型错误:词形还原 nltk 中的预期字符串或类似字节的 object - TypeError: expected string or bytes-like object in lemmatization nltk 在文本文件中搜索字符串时出现“ TypeError:预期字符串或类似字节的对象”错误-Python - 'TypeError: expected string or bytes-like object' error while searchin string in text file-Python TypeError: 预期的字符串或类似字节的 object – 使用 Python/NLTK word_tokenize - TypeError: expected string or bytes-like object – with Python/NLTK word_tokenize 抓取网站时出现“ TypeError:预期的字符串或类似字节的对象” - 'TypeError: expected string or bytes-like object' while scraping a site TypeError:预期的字符串或类似字节的对象(Python) - TypeError: expected string or bytes-like object(Python) 情感分析Python TypeError:预期的字符串或类似字节的对象 - Sentiment analysis Python TypeError: expected string or bytes-like object python正则表达式错误:TypeError:预期的字符串或类似字节的对象 - python regex error : TypeError: expected string or bytes-like object TypeError:Python中预期的字符串或类似字节的对象 - TypeError: expected string or bytes-like object in Python Python 错误:TypeError:预期的字符串或类似字节的对象 - Python error: TypeError: Expected string or bytes-like object Python3 返回 TypeError: 预期的字符串或类似字节的 object - Python3 returning TypeError: expected string or bytes-like object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM