简体   繁体   中英

read_excel or read_csv on pandas

I tried the pandas method but it doesn't work. The name of my file is 'Classeur1'. I can't load it on Jupyter or Spyder.

import pandas as pd

df = pd.read_csv("TP 2 FIN 3500.xlsx")

df.head()

I get:

  File "<ipython-input-1-2b6f31d9e40c>", line 1, in <module>
    runfile('C:/Users/alber/.spyder-py3/temp.py', wdir='C:/Users/alber/.spyder-py3')

  File "C:\Users\alber\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\Users\alber\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/alber/.spyder-py3/temp.py", line 2, in <module>
    df = pd.read_csv("TP 2 FIN 3500.xlsx")

  File "C:\Users\alber\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 685, in parser_f
    return _read(filepath_or_buffer, kwds)

  File "C:\Users\alber\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 457, in _read
    parser = TextFileReader(fp_or_buf, **kwds)

  File "C:\Users\alber\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 895, in __init__
    self._make_engine(self.engine)

  File "C:\Users\alber\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1135, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)

  File "C:\Users\alber\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1917, in __init__
    self._reader = parsers.TextReader(src, **kwds)

  File "pandas\_libs\parsers.pyx", line 382, in pandas._libs.parsers.TextReader.__cinit__

  File "pandas\_libs\parsers.pyx", line 689, in pandas._libs.parsers.TextReader._setup_parser_source

FileNotFoundError: [Errno 2] File b'TP 2 FIN 3500.xlsx' does not exist: b'TP 2 FIN 3500.xlsx'

I also tried both method with the absolute: C:\Users\alber\Documents\Downloads\python stockage

Unable to load file using pandas dataframe

Thanks !

For reading excel try this.

df = pd.read_excel("TP 2 FIN 3500.xlsx")

If Classeur1 is CSV file then try this.

df = pd.read_excel("Classeur1.csv")

Also, check if the file is placed in the same directory as the notebook, for it to be found.

你读取excel文件如下:

df = pd.read_excel (r'Path where the Excel file is stored\File name.xlsx')

If you are using pd.read_csv() then convert your excel file to .CSV formate. Aslo put your excel or .csv file in this directory: C:\\Users\\alber.

df= pd.read_csv("your_filename.csv")

You can also use one more method by changing your jupyter running directory path by using below code:-

os.chdir('D:\folder_path_of_csv_file')
print(os.getcwd())
df= pd.read_csv("your_filename.csv")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM