DataFrame.items()
create an iteration object for DataFrame
, which allows it to iterate each column of the DataFrame
. This method works similarly to the DataFrame.iteritems()
method, which displays each column's name and content as a Series
.
The syntax for using this method is as follows:
Dataframe.items()
The DataFrame.items()
does not take any parameters.
It returns a tuple that contains:
label:
The column name.content:
The column entries belonging to each label, as a pandas Series
object.In the code snippet, we'll create a DataFrame
and then invoke Dataframe.items()
to get column names and data separately:
#Import Panda moduleimport pandas as panda# data as dictionaryrecord = {"Employee_Name": ["Jenifer", "Amenda", "Yuonne"],"Department": ["Finance", "Fintech", "Software"],"Designation":["Assistant Manager","Employee","Project Manager"],"Salary": [12000 , 87000,45000]}# creating Dataframe objectdataframe = panda.DataFrame(record)# iteration for columns label and its contentsfor Label, Content in dataframe.items():# Print data as label and seriesprint(Label)print(Content)
panda
module. DataFrame
object to assign data to it. for
loop with variables Label
and Content
to get the column title and its contents using the items()
method.