Pandas DataFrame.columns Last Updated : 14 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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.Retrieve Column Labels Using DataFrame.columns Here's an example showing how to use DataFrame.columns in order to obtain column labels from a DataFrame. Python import pandas as pd df = pd.DataFrame({ 'Weight': [45, 88, 56, 15, 71], 'Name': ['Sam', 'Andrea', 'Alex', 'Robin', 'Kia'], 'Age': [14, 25, 55, 8, 21] }) index_ = ['Row_1', 'Row_2', 'Row_3', 'Row_4', 'Row_5'] df.index = index_ print("DataFrame:") display(df) result = df.columns print("\n Name of Columns of Pandas DataFrame") print(result) Output: Column Labels retrieved Using DataFrame.columns 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: Python import pandas as pd df = pd.DataFrame({ "A": [12, 4, 5, None, 1], "B": [7, 2, 54, 3, None], "C": [20, 16, 11, 3, 8], "D": [14, 3, None, 2, 6] }) idx = ['Row_1', 'Row_2', 'Row_3', 'Row_4', 'Row_5'] df.index = idx res = df.columns print("\n Name of Columns of Pandas DataFrame") print(res) Output 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.Why Use DataFrame.columns?Access Column Names: Easily access the column labels of a DataFrame for further analysis.Manipulate Columns: You can modify the DataFrame.columns attribute to rename columns as needed.Inspect Data: Quickly inspect and confirm the column names to ensure accurate data processing.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:Pandas TutorialPandas DataFrame.columns Comment More infoAdvertise with us Next Article Pandas DataFrame.columns S Shubham__Ranjan Follow Improve Article Tags : Python Python-pandas Python pandas-dataFrame Pandas-DataFrame-Methods Practice Tags : python Similar Reads Pandas Dataframe/Series.head() method - Python The head() method structure and contents of our dataset without printing everything. By default it returns the first five rows but this can be customized to return any number of rows. It is commonly used to verify that data has been loaded correctly, check column names and inspect the initial record 3 min read Pandas Dataframe/Series.tail() method - Python The tail() method allows us to quickly preview the last few rows of a DataFrame or Series. This method is useful for data exploration as it helps us to inspect the bottom of the dataset without printing everything. By default it returns the last five rows but this can be customized to return any num 3 min read Pandas Dataframe.sample() | Python Pandas DataFrame.sample() function is used to select randomly rows or columns from a DataFrame. It proves particularly helpful while dealing with huge datasets where we want to test or analyze a small representative subset. We can define the number or proportion of items to sample and manage randomn 2 min read Python | Pandas dataframe.info() When working with data in Python understanding the structure and content of our dataset is important. The dataframe.info() method in Pandas helps us in providing a concise summary of our DataFrame and it quickly assesses its structure, identify issues like missing values and optimize memory usage.Ke 2 min read Pandas DataFrame dtypes Property | Find DataType of Columns Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Pandas DataFrame.dtypes attribute returns a series with the data type of each column.Example:Pythonimport pandas as pd df = pd.DataFrame({'Weight': [45, 88, 56, 3 min read Pandas df.size, df.shape and df.ndim Methods Understanding structure of our data is an important step in data analysis and Pandas helps in making this easy with its df.size, df.shape and df.ndim functions. They allow us to identify the size, shape and dimensions of our DataFrame. In this article, we will see how to implement these functions in 2 min read Pandas DataFrame describe() Method The describe() method in Pandas generates descriptive statistics of DataFrame columns which provides key metrics like mean, standard deviation, percentiles and more. It works with numeric data by default but can also handle categorical data which offers insights like the most frequent value and the 4 min read Python | Pandas Series.unique() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages, and makes importing and analyzing data much easier. While analyzing the data, many times the user wants to see the unique values in a par 1 min read Pandas dataframe.nunique() Method Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas DataFrame.nunique Syntax Pandas dataframe.nunique() function returns a Series 2 min read Python | Pandas Series.isnull() Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.isnull() function detect missi 2 min read Like