Loading a csv file using pandas - python

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

Related

Why am I not able to import data using Pandas in Python?

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?

Cannot import Excel sheet into Jupyter Notebook

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)

pandas read_csv producing "IOError: Initializing from file failed" error. How do I fix this?

I have not been able to get pandas read_csv function to work on Mac. It does not matter how the file path is configured, or what csv file I am trying to use (I have used multiple files). It always results in IOError: Initializing from file failed. I have no clue what to try. This is the format I am using.
df = pd.read_csv(r'/Users/me/Documents/file.csv')
I have tried changing the working directory and using df = pd.read_csv('file.csv'), but this produces the same error.

Basic Importing Excel Documents Into Python

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')

Pandas excel reading buffer error (python 3)

I am having a problem reading an excel file from a download link using pandas. The excelString below loads correctly and looks like an excel file, but when trying to convert it to excel using pandas it says the file name is too long. Any assistance would be appreciated. This is a useful generic problem to solve for anyone accessing iShares index membership info.
import urllib
import pandas as pd
f = urllib.request.urlopen('https://www.ishares.com/us/239714/fund-download.dl')
excelString = f.read().decode('utf-8')
pd.ExcelFile(excelString)
The Error returned is OSError: [Errno 36] File name too long
Works fine for me using Python3 and pandas 0.16.2 - do you have the latest version?

Categories

Resources