- API reference
- DataFrame
- pandas.DataF...
pandas.DataFrame.items#
- DataFrame.items()[source]#
Iterate over (column name, Series) pairs.
Iterates over the DataFrame columns, returning a tuple withthe column name and the content as a Series.
- Yields:
- labelobject
The column names for the DataFrame being iterated over.
- contentSeries
The column entries belonging to each label, as a Series.
See also
DataFrame.iterrows
Iterate over DataFrame rows as (index, Series) pairs.
DataFrame.itertuples
Iterate over DataFrame rows as namedtuples of the values.
Examples
>>>df=pd.DataFrame({'species':['bear','bear','marsupial'],...'population':[1864,22000,80000]},...index=['panda','polar','koala'])>>>df species populationpanda bear 1864polar bear 22000koala marsupial 80000>>>forlabel,contentindf.items():...print(f'label:{label}')...print(f'content:{content}',sep='\n')...label: speciescontent:panda bearpolar bearkoala marsupialName: species, dtype: objectlabel: populationcontent:panda 1864polar 22000koala 80000Name: population, dtype: int64
On this page