Skip to content Skip to sidebar Skip to footer

Using Pandas To Find Daily Averages

I'm currently writing a code that takes in a .csv file that appears as so: 724070 93730 19800101 0 330 1.5 22000 -1.7 -5 1013.6 78 724070 93730 19800101 100 230 1.

Solution 1:

Creating mean values by observations is fairly simple. Notice that this is not a concept that is specific to dates, you basically want to create mean-values using some values as group-identifier. Standard code for this is

df = pd.DataFrame(data)
means = df.groupby('DATE').mean()

If you want to separate your data based on three values 'a1', 'a2', 'a3' of a column called 'A', one way to proceed would be

data1 = df[df['A'] == 'a1']
data2 = df[df['A'] == 'a2']
data3 = df[df['A'] == 'a3']

You can do this onto any dataframe - also the one that I earlier called means. However, if the calculations that you want to do are the same for the different stations, it does not make sense to separate the data sets. What I would rather do is keep the dataset together, do all the operations, and do not split before looking at results and/or plotting. That is cleaner, imo.

As for identifying columns as dates, I believe this is a question that has been asked (and answered) quite often here.

Post a Comment for "Using Pandas To Find Daily Averages"