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:



Crime



My current info is shown as this:
Crime Info



<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')


enter image description here



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)


Closer but still not ideal










share|improve this question









New contributor




ComSci Student is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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















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:



Crime



My current info is shown as this:
Crime Info



<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')


enter image description here



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)


Closer but still not ideal










share|improve this question









New contributor




ComSci Student is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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













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:



Crime



My current info is shown as this:
Crime Info



<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')


enter image description here



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)


Closer but still not ideal










share|improve this question









New contributor




ComSci Student is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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:



Crime



My current info is shown as this:
Crime Info



<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')


enter image description here



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)


Closer but still not ideal







python pandas anaconda geopandas






share|improve this question









New contributor




ComSci Student is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




ComSci Student is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday





















New contributor




ComSci Student is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









ComSci Student

433




433




New contributor




ComSci Student is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





ComSci Student is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






ComSci Student is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 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




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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






ComSci Student is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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





































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.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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




















































































Popular posts from this blog

Bressuire

Vorschmack

Quarantine