I am trying to import an Excel sheet from my computer into Jupyter Notebook. I am using the below code:
import pandas as pd
df = pd.read_excel(r'C:\Users\User\Desktop\ALL my folders\Budget_2021_Twinsies.xlsx')
I get a lengthy error code, the essence of which is:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\User\\Desktop\\ALL my folders\\Budget_2021_Twinsies.xlsx'
I do have this file on my computer and I type in the correct directory, yet still get this error.
Could anyone shed some light?
The best practice is to use the pathlib module function that always select the correct configuration for your OS.
import pandas as pd
import pathlib
file = pathlib.Path(mydir, myfile)
df = pd.read_excel(file)
Related
I'm trying to load a csv file in google colab with pandas. I've tried many different ways now and I keep getting the same error message every time:
import pandas as pd
df = pd.read_csv('C:/Users/renat/Documentos/pandas/pokemon_data.csv')
I've also tried with \ , and placing an 'r' before 'C:
The traceback error is
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/renat/Documentos/pandas/pokemon_data.csv'
Try changing ur working directory first
I'm trying to create a dataframe using a csv file for an assignment however, every time I would run my program it would show me an error that the file couldn't be found. My code is the following:
import pandas as pd
df = pd.read_csv('thefile')
The code returns an error no matter where I place my file. When I checked for the path using the code below:
import os
print(os.getcwd())
It showed me that the path is correct and it is looking inside the folder where my csv file is located but it still returns me the same error.
When reading in files, the 'thefile' must be followed by a .csv extension in the reference, as follows; 'thefile.csv'.
You need to add .csv behind the thefile,
without it, it doesn't know which file to look for it could be thefile.txt, thefile.conf, thefile.csv, thefile.....
So your code should look like this.
import pandas as pd
df = pd.read_csv('thefile.csv')
I am a very beginner in python, I started learning only a few weeks ago.
I am working on jupyter notebook and try to do the following:
import pandas as pd
health_data = pd.read_csv("data.csv", header=0, sep=",")
print(health_data)
however I get a very long error message, ending with: FileNotFoundError: [Errno 2] No such file or directory: 'data.csv'
I have tried to read some explanations of this common issue here on stackoverflow but still cannot get my way around it.
Have you made sure that 'data.csv' is in the same directory where you have the current .ipynb file?
I'm a new Python user and am simply trying to export an Excel (or CSV) file into Jupyter Notebook to play around with.
From google searching, the common code I see is something like the below:
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile
df = pd.read_excel('File.xlsx', sheetname='Sheet1')
print("Column headings:")
print(df.columns)
I tried this with a CSV file and got the below error message:
File "", line 5
df = pd.read_excel(C:\Users\dhauge1\Desktop\Python Workshop\fortune500.csv, sheetname=fortune500)
^ SyntaxError: invalid syntax
Please see above for error message. Is anyone able to help me understand what I'm doing wrong?
when reading a csv file use the comand pd.read_csv('filename')
I am trying to read into a pandas dataframe from a csv. The data is in the format:
date,total_bytes
2018-08-27,1.84E+14
2018-08-30,1.90E+14
2018-08-31,1.93E+14
My code looks like:
from pandas import read_csv
from pandas import datetime
from matplotlib import pyplot
series =
read_csv(r'/Users/taylorjewell/Desktop/dataset_size_daily.csv',
header=0)
print(series.head())
series.plot()
pyplot.show()
Despite that path existing (I have checked countless times), I am getting a file not found exception for some reason:FileNotFoundError: File b'/Users/taylorjewell/Desktop/dataset_size_daily' does not exist
I am running this on a mac if that is relevant. Any help you are able to offer would be much appreciated!!
For file paths, I would suggest using pathlib:
from pathlib import Path
data_file = Path("/Users/taylorjewell/Desktop/dataset_size_daily.csv")
series = read_csv(data_file, header=0)
However, it also depends on where you are trying to access the file from.
i dont think you need to use the r bit for mac
try
read_csv('/Users/taylorjewell/Desktop/dataset_size_daily.csv',
header=0)
Just ran into this issue today and wanted to share-
If you download a CSV file to a mac
But then open the file and save it
The file extension changes to .numbers
So make sure you just move the file without opening it, and double-check that the file extension is .csv