读取CSV文件

问题描述

import numpy as np
import pandas as pd

df = pd.read_csv('/content/Glassdoor Reviews.csv',encoding='latin1',error_bad_lines=False,sep=';')
df.head()

nullcheck=df.isnull().sum()
print(nullcheck)

count=df['Category'].value_counts()
print(count)

from sklearn.model_selection import train_test_split
X = df['Review']  # this time we want to look at the text
y = df['Category']
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=20)
                   ERROR

` 分类评论,备注0 dtype:int64 b'跳过第170行:预期1场,看到2 \ n'

KeyError跟踪(最近一次通话最近) get_loc中的/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py(自身,键,方法,公差) 2645试试: -> 2646返回self._engine.get_loc(key) 2647除了KeyError:

pandas._libs.index.IndexEngine.get_loc()中的

pandas / _libs / index.pyx

pandas._libs.index.IndexEngine.get_loc()中的

pandas / _libs / index.pyx

pandas中的pandas / _libs / hashtable_class_helper.pxi._libs.hashtable.PyObjectHashTable.get_item()

pandas中的pandas / _libs / hashtable_class_helper.pxi._libs.hashtable.PyObjectHashTable.get_item()

KeyError:'类别'

在处理上述异常期间,发生了另一个异常:

KeyError跟踪(最近一次通话最近) 2帧 get_loc中的/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py(自身,键,方法,公差) 2646返回self._engine.get_loc(键) 2647除了KeyError: -> 2648返回self._engine.get_loc(self._maybe_cast_indexer(key)) 2649 indexer = self.get_indexer([key],method = method,tolerance = tolerance) 2650,如果indexer.ndim> 1或indexer.size> 1:

pandas._libs.index.IndexEngine.get_loc()中的

pandas / _libs / index.pyx

pandas._libs.index.IndexEngine.get_loc()中的

pandas / _libs / index.pyx

pandas中的pandas / _libs / hashtable_class_helper.pxi._libs.hashtable.PyObjectHashTable.get_item()

pandas中的pandas / _libs / hashtable_class_helper.pxi._libs.hashtable.PyObjectHashTable.get_item()

KeyError:“类别” `

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)