What are other DataFrame attributes?

089

In pandas, a DataFrame has several attributes that provide information about the DataFrame or allow you to manipulate it. Here are some commonly used attributes:

  1. .shape: Returns a tuple representing the dimensions of the DataFrame (number of rows, number of columns).

    df.shape
  2. .columns: Returns the column labels of the DataFrame.

    df.columns
  3. .index: Returns the index (row labels) of the DataFrame.

    df.index
  4. .dtypes: Returns the data types of each column in the DataFrame.

    df.dtypes
  5. .info(): Provides a summary of the DataFrame, including the index dtype, column dtypes, non-null values, and memory usage.

    df.info()
  6. .head(n): Returns the first n rows of the DataFrame (default is 5).

    df.head()
  7. .tail(n): Returns the last n rows of the DataFrame (default is 5).

    df.tail()
  8. .T: Transposes the DataFrame (swaps rows and columns).

    df.T

These attributes can help you understand and manipulate your DataFrame effectively.

0 Comments

no data
Be the first to share your comment!