如何在Google collab中使用python从CSV文件中读取特定列


df = pd.read_csv(io.BytesIO(uploaded['data.csv']))

ParserError                               Traceback (most recent call last)
<ipython-input-22-a523fd2e8c08> in <module>()
1 import io
2 
----> 3 df = pd.read_csv(io.BytesIO(uploaded['data.csv']))
4 
5 
3 frames
/usr/local/lib/python3.7/dist-packages/pandas/io/parsers.py in read(self, nrows)
2155     def read(self, nrows=None):
2156         try:
-> 2157             data = self._reader.read(nrows)
2158         except StopIteration:
2159             if self._first_chunk:
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.read()
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._read_low_memory()
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._read_rows()
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._tokenize_rows()
pandas/_libs/parsers.pyx in pandas._libs.parsers.raise_parser_error()
ParserError: Error tokenizing data. C error: Expected 3 fields in line 77, saw 5
import pandas as pd #import pandas
fread =  pd.read_csv('filepath/filename.csv') #make fread as object
freaddf = pd.DataFrame(fread, columns=['col1name', 'col2name', 'col3name'])
print(freaddf.to_string())

相关内容

  • 没有找到相关文章

最新更新