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