columns

This attribute is used to fetch the label values for columns present in a particular data frame.

Syntax: dataframe_name.columns 

Python3




# Python program to implement
# columns attribute in a dataframe object
import pandas as pd
 
# Creating a 2D dictionary having values as
# dictionary object
dict = {"Sales": {'Name': 'Shyam',
                  'Age': 23, 'Gender': 'Male'},
        "Marketing": {'Name': 'Neha',
                      'Age': 22, 'Gender': 'Female'}}
 
# Creating a data frame object
data_frame = pd.DataFrame(dict)
 
# printing this data frame on output screen
display(data_frame)
 
# Implementing index attribute for this
# data frame
print(data_frame.columns)


Output:

In this program, we have made a DataFrame from a 2D dictionary having values as dictionary object and then printed this DataFrame on the output screen and at the end of the program, we have implemented column attribute as print(data_frame.columns) to print the column labels of this DataFrame. In this program, column labels are “Marketing and Sales” so it will print the same.

Dataframe Attributes in Python Pandas

In this article, we will discuss the different attributes of a dataframe. Attributes are the properties of a DataFrame that can be used to fetch data or any information related to a particular dataframe.

The syntax of writing an attribute is:

DataFrame_name.attribute

These are the attributes of the dataframe:

  • index
  • columns
  • axes
  • dtypes
  • size
  • shape
  • ndim
  • empty
  • T
  • values

Similar Reads

index

There are two types of index in a DataFrame one is the row index and the other is the column index. The index attribute is used to display the row labels of a data frame object. The row labels can be of 0,1,2,3,… form and can be of names....

columns

...

axes

...

dtypes

This attribute is used to fetch the label values for columns present in a particular data frame....

size

...

shape

This attribute is used when we want to fetch the values of all row labels and all column labels at a time....

ndim

...

empty

The purpose of this attribute is to display the data type for each column of a particular dataframe....

T (Transpose)

...

values

This attribute is used to display the total number of elements or items present in a data frame....