neuniversity / ALY6140

1 stars 3 forks source link

Count values within a timeframe #43

Open richardshiii opened 5 years ago

richardshiii commented 5 years ago

Hi all,

My dataset contains different types of crime and when they happened (in which year). I would like to count the number of a specific type of crime happened in each year. Does anyone has any ideas on how do write the codes?

Thanks a lot!

Kewei

CHENGYULIU1 commented 5 years ago

If I understand correctly, you can just use groupby function.

.groupby("types of crime " , "year ").size()

xyz04 commented 5 years ago

I think groupby function is a kind of way to deal with your problem. In this way, you will know the number of the type of crimes is each year. ...groupby("type of crime","year").size() Hope that will help you.

YantingGuo commented 5 years ago

I solved a similar problem by creating a new dataframe to reflect the data that I want to count, then type the code len() to know how many rows it has! I think groupby can solve this problem as well!