Pandas - Plotting out crime by month on graph
up vote
0
down vote
favorite
so I'm trying to plot out a graph using geopandas but I'm in this situation where I'm trying to figure out how to do it correctly. I would like to plot my graph similar to this:
My current info is shown as this:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 313601 entries, 0 to 313600
Data columns (total 6 columns):
Month 313601 non-null object
Reported by 313601 non-null object
Longitude 313601 non-null float64
Latitude 313601 non-null float64
Location 313601 non-null object
Crime type 313601 non-null object
dtypes: float64(2), object(4)
memory usage: 14.4+ MB
Attempt:
monthlyCrime = df["Month"].value_counts(ascending=False)
print(monthlyCrime)
plt.figure(figsize=(11,5))
plt.plot(monthlyCrime.index, monthlyCrime.values)
plt.xticks(rotation=90)
#Add description
plt.title('Number of crimes per month (2016)')
plt.xlabel('Months')
plt.ylabel('Number of crimes')
Therefore I would like to have it so the crime type and month are linked, my attempts have been pretty bleak so far. I know there is a count feature and I have tried it, but I didn't get it in the correct order and I'm unsure how I would then apply it to the graph. Would anyone know what I would need to do? Thank you.
UPDATE:
So this is what I was able to do:
crimeDataMonthGroup = pd.DataFrame({'count' : crimeDataMonth.groupby([ "Month"] ).size()}).reset_index()
#df1 = df.groupby([ "Crime type", "Month"]).count().reset_index(name='count')
print(crimeDataMonthGroup)
tb = pd.pivot_table(crimeDataMonthGroup, values='count', index=['Month'], fill_value=0)
tb.plot(figsize=(15, 13), subplots=True, sharex=False, sharey=False)
python pandas anaconda geopandas
New contributor
add a comment |
up vote
0
down vote
favorite
so I'm trying to plot out a graph using geopandas but I'm in this situation where I'm trying to figure out how to do it correctly. I would like to plot my graph similar to this:
My current info is shown as this:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 313601 entries, 0 to 313600
Data columns (total 6 columns):
Month 313601 non-null object
Reported by 313601 non-null object
Longitude 313601 non-null float64
Latitude 313601 non-null float64
Location 313601 non-null object
Crime type 313601 non-null object
dtypes: float64(2), object(4)
memory usage: 14.4+ MB
Attempt:
monthlyCrime = df["Month"].value_counts(ascending=False)
print(monthlyCrime)
plt.figure(figsize=(11,5))
plt.plot(monthlyCrime.index, monthlyCrime.values)
plt.xticks(rotation=90)
#Add description
plt.title('Number of crimes per month (2016)')
plt.xlabel('Months')
plt.ylabel('Number of crimes')
Therefore I would like to have it so the crime type and month are linked, my attempts have been pretty bleak so far. I know there is a count feature and I have tried it, but I didn't get it in the correct order and I'm unsure how I would then apply it to the graph. Would anyone know what I would need to do? Thank you.
UPDATE:
So this is what I was able to do:
crimeDataMonthGroup = pd.DataFrame({'count' : crimeDataMonth.groupby([ "Month"] ).size()}).reset_index()
#df1 = df.groupby([ "Crime type", "Month"]).count().reset_index(name='count')
print(crimeDataMonthGroup)
tb = pd.pivot_table(crimeDataMonthGroup, values='count', index=['Month'], fill_value=0)
tb.plot(figsize=(15, 13), subplots=True, sharex=False, sharey=False)
python pandas anaconda geopandas
New contributor
So as you can see, I was able to plot them out but I would like them to be in the same format where I had the year in the bottom and then it goes up and down depending on the month.
– ComSci Student
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
so I'm trying to plot out a graph using geopandas but I'm in this situation where I'm trying to figure out how to do it correctly. I would like to plot my graph similar to this:
My current info is shown as this:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 313601 entries, 0 to 313600
Data columns (total 6 columns):
Month 313601 non-null object
Reported by 313601 non-null object
Longitude 313601 non-null float64
Latitude 313601 non-null float64
Location 313601 non-null object
Crime type 313601 non-null object
dtypes: float64(2), object(4)
memory usage: 14.4+ MB
Attempt:
monthlyCrime = df["Month"].value_counts(ascending=False)
print(monthlyCrime)
plt.figure(figsize=(11,5))
plt.plot(monthlyCrime.index, monthlyCrime.values)
plt.xticks(rotation=90)
#Add description
plt.title('Number of crimes per month (2016)')
plt.xlabel('Months')
plt.ylabel('Number of crimes')
Therefore I would like to have it so the crime type and month are linked, my attempts have been pretty bleak so far. I know there is a count feature and I have tried it, but I didn't get it in the correct order and I'm unsure how I would then apply it to the graph. Would anyone know what I would need to do? Thank you.
UPDATE:
So this is what I was able to do:
crimeDataMonthGroup = pd.DataFrame({'count' : crimeDataMonth.groupby([ "Month"] ).size()}).reset_index()
#df1 = df.groupby([ "Crime type", "Month"]).count().reset_index(name='count')
print(crimeDataMonthGroup)
tb = pd.pivot_table(crimeDataMonthGroup, values='count', index=['Month'], fill_value=0)
tb.plot(figsize=(15, 13), subplots=True, sharex=False, sharey=False)
python pandas anaconda geopandas
New contributor
so I'm trying to plot out a graph using geopandas but I'm in this situation where I'm trying to figure out how to do it correctly. I would like to plot my graph similar to this:
My current info is shown as this:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 313601 entries, 0 to 313600
Data columns (total 6 columns):
Month 313601 non-null object
Reported by 313601 non-null object
Longitude 313601 non-null float64
Latitude 313601 non-null float64
Location 313601 non-null object
Crime type 313601 non-null object
dtypes: float64(2), object(4)
memory usage: 14.4+ MB
Attempt:
monthlyCrime = df["Month"].value_counts(ascending=False)
print(monthlyCrime)
plt.figure(figsize=(11,5))
plt.plot(monthlyCrime.index, monthlyCrime.values)
plt.xticks(rotation=90)
#Add description
plt.title('Number of crimes per month (2016)')
plt.xlabel('Months')
plt.ylabel('Number of crimes')
Therefore I would like to have it so the crime type and month are linked, my attempts have been pretty bleak so far. I know there is a count feature and I have tried it, but I didn't get it in the correct order and I'm unsure how I would then apply it to the graph. Would anyone know what I would need to do? Thank you.
UPDATE:
So this is what I was able to do:
crimeDataMonthGroup = pd.DataFrame({'count' : crimeDataMonth.groupby([ "Month"] ).size()}).reset_index()
#df1 = df.groupby([ "Crime type", "Month"]).count().reset_index(name='count')
print(crimeDataMonthGroup)
tb = pd.pivot_table(crimeDataMonthGroup, values='count', index=['Month'], fill_value=0)
tb.plot(figsize=(15, 13), subplots=True, sharex=False, sharey=False)
python pandas anaconda geopandas
python pandas anaconda geopandas
New contributor
New contributor
edited yesterday
New contributor
asked yesterday
ComSci Student
433
433
New contributor
New contributor
So as you can see, I was able to plot them out but I would like them to be in the same format where I had the year in the bottom and then it goes up and down depending on the month.
– ComSci Student
yesterday
add a comment |
So as you can see, I was able to plot them out but I would like them to be in the same format where I had the year in the bottom and then it goes up and down depending on the month.
– ComSci Student
yesterday
So as you can see, I was able to plot them out but I would like them to be in the same format where I had the year in the bottom and then it goes up and down depending on the month.
– ComSci Student
yesterday
So as you can see, I was able to plot them out but I would like them to be in the same format where I had the year in the bottom and then it goes up and down depending on the month.
– ComSci Student
yesterday
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
ComSci Student is a new contributor. Be nice, and check out our Code of Conduct.
ComSci Student is a new contributor. Be nice, and check out our Code of Conduct.
ComSci Student is a new contributor. Be nice, and check out our Code of Conduct.
ComSci Student is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238545%2fpandas-plotting-out-crime-by-month-on-graph%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
So as you can see, I was able to plot them out but I would like them to be in the same format where I had the year in the bottom and then it goes up and down depending on the month.
– ComSci Student
yesterday