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];
1;Russia;17,098,242,00;
2;Antarctica;14,200,000,00;
3;Canada;9,984,670,00;
4;United States;9,833,517,00;
5;China;9,596,960,00;
6;Brazil;8,515,770,00;
7;Australia;7,741,220,00;
8;India;3,287,263,00;
9;Argentina;2,780,400,00;
10;Kazakhstan;2,724,900,00;
11;Algeria;2,381,740,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!
Andi

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?

!dir
!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.

Thanks!

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=";")