Get List of Column Names Grouped by Data Type in Python (Example) | to_series() & groupby() Function

Published: 23 December 2022
on channel: Statistics Globe
97
4

How to return a list of column names grouped by the type of the column in the Python programming language. More details: https://statisticsglobe.com/get-list-...
Python code of this video:

import pandas as pd # Import pandas library in Python

data = pd.DataFrame({'x1':['a', 'b', 'c', 'd', 'e'], # Create example DataFrame
'x2':range(6, 1, - 1),
'x3':[2, 5, 5, 8, 3],
'x4':['x', 'x', 'x', 'x', 'x'],
'x5':range(1, 6)})
print(data) # Print example DataFrame

print(data.columns.to_series().groupby(data.dtypes).groups)
{int64: ['x2', 'x3', 'x5'], object: ['x1', 'x4']}

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe  
Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – R Programming Group for Discussions & Questions:   / 12555223  
LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534  
Twitter:   / joachimschork  

Music by bensound.com


On this page of the site you can watch the video online Get List of Column Names Grouped by Data Type in Python (Example) | to_series() & groupby() Function with a duration of hours minute second in good quality, which was uploaded by the user Statistics Globe 23 December 2022, share the link with friends and acquaintances, this video has already been watched 97 times on youtube and it was liked by 4 viewers. Enjoy your viewing!