Home > Blockchain >  How do i make a data that is using .count()) become a new pandas data table
How do i make a data that is using .count()) become a new pandas data table

Time:08-13

I saw before how you can count age from this page of stack overflow, but how do i make data that has been processed into another column.

 age_data_array_1 = pd.DataFrame({'Age':age_data_list_1})
 bins = [0, 20, 30, 40, 50, 60, 110]
 age_labels = ['Less than 20', '20 years', '30 years', '40 years', '50 years', 'more_than_60']
 age_data_array_1['Age_Group'] = pd.cut(age_data_array_1['Age'], bins=bins, labels=age_labels, right = False)
 age_data_array_1['Age_Group'] = age_data_array_1['Age_Group'].cat.add_categories('invalid').fillna('invalid')
 divide_by_age_group = age_data_array_1.groupby('Age_Group')
 print(divide_by_age_group.count())

How do i make the divide_by_age_group.count()) become a new pandas data

Python Pandas <pandas.core.groupby.DataFrameGroupBy object at ...>

CodePudding user response:

I might be misunderstanding your question but don't you just need:

df_count = divide_by_age_group.count()

CodePudding user response:

turns out its as easy as df_1 = pd.DataFrame(divide_by_age_group)

  • Related