To start with - I'm a total beginner with Pandas, so descriptive help would be very appreciated.
I have one dataframe, called df_persons. This dataframe contains 2 columns, one "age" and one "gender". The ages spans from 0 - 100 yrs.
My main goal is to create a pie chart, showing amount of people who's in a certain age group.
What I wanted to do was to create a new dataframe, with 3 columns. Lets say I want to name this new dataframe test_df.
"Under 18" "Between 18 - 40" "Between 40-60" "60+"
In order to achieve this, I have tried the following:
test_df['Under 18'] = df[(person_df['Age'] >=18]
But without success.
I managed to get the columns in place by doing:
test_df['Under 18'] = df_person['Age']
But I have not been able to populate my 4 new columns, based on the dataframe I need to pull the information from.
test_df = pd.DataFrame(columns=['Under 18', 'Between 18 -40', 'Between 40-60', 'Over 60'])
test_df['Under 18'] =test_df['Under 18'].astype(str).astype(int)
test_df['Under 18'] = df_person[df_person['Age']>18]
What is the best approach in achieving this? Any help/tips / recommendations are very welcome.