PD.READ_CSV - doesnt find

Hi DQ Team,

I have a very embarissing question. I do not understand why I am not finding a Excel (.csv) which is located as other Excels in the same Folder.
I can also open it in my Jupyter looking as such:
Country;Comparison;Area [SQ KM];
4;United States;9,833,517,00;
12;Congo, Democratic Republic of the;2,344,858,00;

Directory: C:\Users\Andreas\data_quest\Datasets\Country Information

Untitled.ipynb (8.7 KB)

Thanks for helping always!

Click here to view the jupyter notebook file in a new tab

1 Like

Hey, Andi.

Can you please add a cell with the following content, rerun the notebook and upload it with the results?

!echo %cd%
!where /R C:\ /T Countries_landmasses.csv

Untitled(1).ipynb (10.4 KB)

Click here to view the jupyter notebook file in a new tab

Well, I mean in on my desktop it shouldnt be :smiley:

I don’t understand this sentence.

Sorry, some of the output seems to be missing. This might be my fault.

Do you mind repeating what you did, only instead of having the three lines of code in one cell, please do one cell per line of code.


No no not your fault for my misunderstanding!

Untitled(2).ipynb (11.1 KB)

I located now the CSV also on my Desktop:

Untitled(3).ipynb (11.1 KB)

Click here to view the jupyter notebook file in a new tab

Why is it showing the directory desktop?

The Notebook(2) is unchanged
And before I created the Notebook(3) I copied the CSV to the Desktop.

Just to see if this works also.
Still I get the same output if I use that directory. Might there be something wrong with the CSV itself?

1 Like

Every time you run a program, it has a starting directory where you’re running it from. Even when you start your browser, there is a starting directory.

Jupyter is no exception. The starting directory is where you’re working by default.

When you try to open a file by passing just a filename, you’re actually using a relative path.

Jupyter doesn’t know that you mean a file that is in another directory. It couldn’t possibly know, because files with the same name could exist in different places in your hard drive, so how could it then choose which one you meant?

Anyway, what is happening here is that you’re running Jupyter from C:\Users\Andreas\Desktop and the file you’re trying to open is in two different locations (different from the working directory, and different between them):

  • C:\Users\Andreas\Data&Quest\Datasets\Country Information\Countries_Landmasses
  • C:\Users\Andreas\data_quest\Datasets\Country Information\Countries_Landmasse

One way to handle this is to refer to one of this files, for instance by running this instead:

df = pd.read_csv(r'C:\Users\Andreas\data_quest\Datasets\Country Information\Countries_Landmasse')

I hope this helps.

I tried.

Still the same issue

Untitled(5).ipynb (18.2 KB)

Click here to view the jupyter notebook file in a new tab

I tried now some more things. All the Excel works.
Still with this file same problem.

Maybe I just try to make a new file?

Untitled(6).ipynb (24.1 KB)

Click here to view the jupyter notebook file in a new tab

This was my mistake. It should have been this:

df = pd.read_csv(r'C:\Users\Andreas\data_quest\Datasets\Country Information\Countries_Landmasse.csv')

I forgot the extension.

Ok so I had to change somehting in the CSV.
Untitled(7).ipynb (21.7 KB)

It was due to a (,) in the Excel sheet:
Congo**,** Democratic Republic of the

But I am surprised, that I still cannot upload that csv and correct that within Jupyter?

Thank you for your help.!

Click here to view the jupyter notebook file in a new tab

This isn’t the same problem :slight_smile:

It’s another problem, as you can see the error is different and it’s telling you what the issue is. You’re not using this function properly.

Try the following instead:

filepath = r'C:\Users\Andreas\data_quest\Datasets\Country Information\Countries_Landmasse.csv'
df = pd.read_csv(filepath, sep=";")