Census Variables

hey, how to solve this part of the project?

1 Like

Welcome to the forums!

Please include a link to the project and post any code that you have already written (please format your code using the </> button).

What aspects of this step are you having trouble with? We’d much rather help you along to figure this out than to simply give you the solution.

2 Likes

https://www.codecademy.com/paths/data-science/tracks/dacp-summary-statistics/modules/stats-variable-types/projects/variables-of-the-census

here is the code of the project

This takes us to our version of that page, which means we still can’t see the code. Can you post it in the forums, and make sure you format it correctly

I have the same problem with part, Can you please provide a guide for this project? thanks

Since this a learning environment it’s unlikely anyone would provide a step by step solution for you. If you browser around the forums and read the following- FAQ: How to ask good questions then you’ll see what kind of queries folks might be able and willing to help with. Break down your problem to its simplest point (minimal working example style) and say what it is you’ve tried to do to solve a problem and you’d likely receive a much better response.

1 Like

This is my code.

census[‘age’] = 2021 - census.birth_year

census[‘age_group’] = (census.age - (census.age % 5))/5

census[‘age_group’]=census[‘age_group’].astype(‘int’)

2 Likes

This furthers the post previous from jiayizhang444 , havnt figured out how to Label individual categories.
Category 2 would be equal to 10-15, Category 3 is equal to 15-20 and so on. Hopefully helps someone in the future

census[‘age’] = 2021 - census.birth_year

census[‘age_group’] = (census.age - (census.age % 5))/5

census[‘age_group’] = census[‘age_group’].astype(‘int’)

#print(census[‘age_group’].sort_values())

#print(census[‘age_group’].unique())

census[‘age_group’] = pd.Categorical(census[‘age_group’],[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], ordered=True)

print(census[‘age_group’])

One more possible solution for you!

import numpy as np
census['age'] = 2021 - census.birth_year
age_bins = np.arange(min(census.age)-4, 100, 5)
census['age_group'] = pd.cut(census.age, bins=age_bins)