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:
-
.shape: Returns a tuple representing the dimensions of the DataFrame (number of rows, number of columns).df.shape -
.columns: Returns the column labels of the DataFrame.df.columns -
.index: Returns the index (row labels) of the DataFrame.df.index -
.dtypes: Returns the data types of each column in the DataFrame.df.dtypes -
.info(): Provides a summary of the DataFrame, including the index dtype, column dtypes, non-null values, and memory usage.df.info() -
.head(n): Returns the firstnrows of the DataFrame (default is 5).df.head() -
.tail(n): Returns the lastnrows of the DataFrame (default is 5).df.tail() -
.T: Transposes the DataFrame (swaps rows and columns).df.T
These attributes can help you understand and manipulate your DataFrame effectively.
