DataFrame – Attributes and Methods

The Pandas DataFrame is a Two-dimensional, tabular data, that uses the DataFrame() method to create a DataFrame. It also uses different built-in attributes and methods for basic functionalities. In this lesson, let us see such attributes and methods in Python Pandas for DataFrame:

  • dtypes: Return the dtypes in the DataFrame
  • ndim: Return the number of dimensions of the DataFrame
  • size: Return the number of elements in the DataFrame.
  • shape: Return the dimensionality of the DataFrame in the form of a tuple.
  • index: Return the index of the DataFrame
  • T: Transpose the rows and columns
  • head(): Return the first n rows.
  • tail(): Return the last n rows.

Let us understand them one by one:

dtypes

The pandas.DataFrame.dtypes is used to return the dtypes in the DataFrame.

Let us now see an example to implement the dtypes attribute in Python Pandas:

Output

ndim

The pandas.DataFrame.ndim is used to return the number of dimensions of the DataFrame.

Let us now see an example to implement the ndim attribute in Python Pandas:

Output

size

The pandas.DataFrame.size is used to return the number of elements in the DataFrame.

Let us now see an example to implement the size attribute in Python Pandas:

Output

shape

The pandas.DataFrame.shape is used to return the dimensionality of the DataFrame in the form of a tuple.

Let us now see an example to implement the shape attribute in Python Pandas:

Output

index

The pandas.DataFrame.index is used to return the index of the DataFrame.

Let us now see an example to implement the index attribute in Python Pandas:

Output

T

The pandas.DataFrame.T is used to Transpose the rows and columns.

Let us now see an example to implement the T attribute in Python Pandas:

Output

head()

The pandas.DataFrame.head() is used to return the first n rows.

Let us now see an example to implement the head() method in Python Pandas:

Output

tail()

The pandas.DataFrame.tail() is used to return the last n rows.

Let us now see an example to implement the tail() method in Python Pandas:

Output

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others:


For Videos, Join Our YouTube Channel: Join Now


Read More:

Pandas Series - Attributes and Methods
Sorting in Pandas
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading