1. Problems encountered:
The source code for reading. CSV is as follows:
import pandas as pd
def main():
aqi_data = pd.read_csv('china_city_aqi.csv')
print(aqi_data.head(5))
if __name__ == "__main__":
main()
The complete error information is as follows:
Traceback (most recent call last):
File "D:/XXX/Python Learning/lect09/AQI_9.0.py", line 14, in <module>
main()
File "D:/XXX/Python Learning/lect09/AQI_9.0.py", line 10, in main
aqi_data = pd.read_csv('china_city_aqi.csv')
File "D:\XXX\Python Learning\lect09\venv\new\lib\site-packages\pandas\io\parsers.py", line 702, in parser_f
return _read(filepath_or_buffer, kwds)
File "D:\XXX\Python Learning\lect09\venv\new\lib\site-packages\pandas\io\parsers.py", line 429, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "D:\XXX\Python Learning\lect09\venv\new\lib\site-packages\pandas\io\parsers.py", line 895, in __init__
self._make_engine(self.engine)
File "D:\XXX\Python Learning\lect09\venv\new\lib\site-packages\pandas\io\parsers.py", line 1122, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "D:\XXX\Python Learning\lect09\venv\new\lib\site-packages\pandas\io\parsers.py", line 1853, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas\_libs\parsers.pyx", line 545, in pandas._libs.parsers.TextReader.__cinit__
pandas.errors.EmptyDataError: No columns to parse from file
2. Solutions
Take a look pandas.read_ The official document of CSV may be related to
Engine: {C ‘,’python’}, optional
Parser engine to use. The C engine is faster while the python engine is currently more feature-complete.
So read_ Add engine = “Python” to the parameter of csv()
The above code is modified as follows:
import pandas as pd
def main():
aqi_data = pd.read_csv('china_city_aqi.csv', engine='python')
print(aqi_data.head(5))
if __name__ == "__main__":
main()
Run successfully after modification!
Read More:
- Pandas read_csv pandas.errors.ParserError: Error tokenizing data
- [Solved] Python Pandas Read Error: OSError: initializing from file failed
- [How to Fix]pandas.errors.ParserError: Error tokenizing data
- How to Fix pandas.errors.ParserError Error tokenizing data C error Buffer overflow caught
- [Solved] AttributeError: module ‘pandas‘ has no attribute ‘rolling_count‘
- Python opens the table and appears pandas.errors.ParserError: Error tokenizing data. C error:
- [Solved] pandas ExcelWrite AttributeError: ‘NoneType‘ object has no attribute ‘group‘
- Python Pandas Error: No module named ‘openpyxl‘
- Python: How to Reshape the data in Pandas DataFrame
- Pandas uses str.contains to filter error [How to Solve]
- Tensorflow import Error: ImportError: libcuda.so.1: cannot open shared object file: No such file or dire
- pandas.DataFrame() Initializes NULL Error: DataFrame [How to Solve]
- Pandas Error: ValueError: setting an array element with a sequence.
- How to Fix Python reading large local file memory error
- PIP Install Mysqlclient error C1083: Cannot open include file: ‘mysql.h‘: No such file or directory
- [Solved] Pandas rename Error: ValueError: operands could not be broadcast together with shapes (1,2) (3,) (1,2)
- Python Pandas Typeerror: invalid type comparison
- Python Pandas Error: KeyError: 0 [How to Solve]
- How to Solve Python Pandas Read or Import Files Error
- [Solved] Python Read bam File Error: &&OSError: no BGZF EOF marker; file may be truncated