1

I have the following graph produced by the code below:

enter image description here

from pandas import *
from ggplot import *

plot = ggplot(data, aes('x','y')) \ #from dataframe 'data', columns x and y
+ geom_bar(stat='bar', fill='blue') + ggtitle('Graph of X and Y') \
+scale_x_continuous(name="X-Axis", breaks=[0, 4, 8, 12, 16, 20, 23], \
                    labels=["Midnight", "4:00am", "8:00am", "12:00pm","4:00pm","8:00pm","11:00pm"])\
+ylab("Y-Axis") + xlim(0, 23) 

print plot

The variable represented by y is a count of the number of events per hour over a period of several weeks. I want to examine the average number of events hourly instead of the total number of events hourly over that time period.

How do I graph the average of 'y' instead of just plotting 'y' using ggplot in Python?

Thanks!

EDIT:

So, I suppose what I really need is a way to get the avg y events per hour (x). Currently, when I try to do so, I return a graph with equal values across all hours.

1 Answer 1

1

I'm not sure where the y values are coming from in your code, but the basic way of averaging any set of data involves adding all the values together, then dividing the sum by the amount of values.

So you might you use a function like this to produce an average from a list of values:

def average(list_):
    output = 0
    for i in list_;
         output += i
    output /= len(list_)
    return output
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your help. I tried it quickly and received some errors. I will work on it a bit and let you know how it goes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.