Question

Python question: the time is from 2016-01-01 ~ 2018-12-31 such as the columns "Month", "Day", "Year"

I need to count how many rows data for each day, and each Borough, such as the column "Borough". The Borough includes: QUEENS, BROOKLYN, BRONX, MANHATTAN, STATEN ISLAND, all together is 5 different Boroughs.

Many Thanks!

Unnamed: 0 Created Date Incident Zip Complaint Type Descriptor Community Board Borough Latitude Longitude Month Day Year 0 19

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import pandas as pd df=pd. read_cs (Records.csv) df Unnamed: Created Date Incident Zip Complaint Type Description Communitymy sample data set

Records.csv х Untitled.ipynb a + X O ► с Code Download GitHub Binder Python 3 [33]: complaintcount=df.groupby([Month, Daycode and output select appropriate one as you need

Code

import pandas as pd
#reading my sample dataset
df=pd.read_csv("Records.csv")

#simple group by with count 
complaintCount=df.groupby(['Month','Day','Year','Borough'])['Complaint Type'].count()
print(complaintCount)
#Group by with changing count column name to 'Complaint Count'
complaintCount=df.groupby(['Month','Day','Year','Borough'])['Complaint Type'].count().reset_index()
complaintCount.rename(columns={'Complaint Type':'Complaint Count'},inplace='True')
print(complaintCount)
Add a comment
Know the answer?
Add Answer to:
Python question: the time is from 2016-01-01 ~ 2018-12-31 such as the columns "Month", "Day", "Year"...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • price time month day year 149.3999939 1 01 02 13 146.5 2 01 03 13 147.3499908...

    price time month day year 149.3999939 1 01 02 13 146.5 2 01 03 13 147.3499908 3 01 04 13 150.3999939 4 01 07 13 148.1499939 5 01 08 13 147.8999939 6 01 09 13 149.6499939 7 01 10 13 153.3499908 8 01 11 13 153.3000031 9 01 14 13 152.5 10 01 15 13 153 11 01 16 13 155.5 12 01 17 13 156.3000031 13 01 18 13 148.5999908 14 01 22 13 150.3999939 15 01 23 13...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT