sari
sari

Reputation: 23

Why is the output of the function shape function wrong?

I imported the library panda to read a csv file. After reading it and printing out the shape it shows me (6,1) even the file has 7 rows and 4 columns.

Here is the code:

import pandas as pd
data = pd.read_csv("C:\Users\Sari\Desktop\username.csv")
print(data.shape)
print(data.head())

The output is the following:

(6, 1)
  username;firstname;lastname;age;hobby
0            miau1;miau1;miau11;1;none1
1            miau2;miau2;miau22;2;none2
2            miau3;miau3;miau33;3;noen3
3            miau4;miau4;miau44;4;none4
4            miau5;miau5;miau55;5;none5

You can see that the file definitely has more than only one column but I still wonder why it shows only (1,6).

Upvotes: 0

Views: 109

Answers (1)

حمزة نبيل
حمزة نبيل

Reputation: 1931

The default separator is , your file use ; as separator you need to specify

The sep argument will be used as separator

data = pd.read_csv("C:\Users\Sari\Desktop\username.csv", sep=";")

Upvotes: 2

Related Questions