![]() |
VOOZH | about |
In Pandas, DataFrame.columns attribute returns the column names of a DataFrame. It gives access to the column labels, returning an Index object with the column labels that may be used for viewing, modifying, or creating new column labels for a DataFrame.
Note: This attribute doesn't require any parameters and simply returns the column labels of the DataFrame when called.
Here's an example showing how to use DataFrame.columns in order to obtain column labels from a DataFrame.
Output:
Letβs take a look at a second example where the DataFrame contains missing values (NaN). To retrieve the column labels from this DataFrame, we use the DataFrame.columns attribute:
Name of Columns of Pandas DataFrame Index(['A', 'B', 'C', 'D'], dtype='object')
As shown, the DataFrame.columns attribute returns the column labels even when the data contains missing values.
The DataFrame.columns attribute in Pandas is an essential tool for managing and working with DataFrame column labels. By using this attribute, users can work efficiently with Pandas DataFrames, whether for data cleaning, transformation, or analysis tasks.
Related Article: