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