import pandas as pd
my_dict={'NAME':['Ravi','Raju','Alex','Ron','King','Jack'],
'ID':[1,2,3,4,5,6],
'MATH':[80,40,70,70,70,30],
'ENGLISH':[80,70,40,50,60,30]}
df = pd.DataFrame(data=my_dict)
print(df.shape)
Output
(6, 4)
As we are getting one tuple as output so we can display the elements to show number of rows ( first elemetn ) and columns ( second element )
print("Number of rows : ",df.shape[0])
print("Number of columns : ",df.shape[1])
Output
Number of rows : 6
Number of columns : 4
print(df.size) # 24
In above code check that the size returns the same value as returned by multiplication of elements returned by shape ( size = rows x columns )
print(df.ndim) # 2
print(df['NAME'].ndim) # 1
import pandas as pd
df = pd.read_excel('D:\student.xlsx')
import pandas as pd
df= pd.read_csv('D:\\my_data\\student.csv') # DataFrame from csv file data
Display the shape, size and ndim
print(df.shape) # (35,5) ( rows, columns)
print("Number of rows : ",df.shape[0])
print("Number of columns : ",df.shape[1])
print(df.size) # 175
print(df.ndim) # 2
print(df['name'].ndim) # 1
Sample student DataFrame Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.