B
B
beesent4402018-04-21 10:51:30
R
beesent440, 2018-04-21 10:51:30

Find the average over a period of time?

There is a dataset with date and temperature on that day. But in the "temperature" column there are also empty NaN values, which must be filled with the AVERAGE VALUE OF TEMPERATURE PER MONTH using Pandas, although the data does not consist of one month, but of several years.
Date Temperature
15.03.2014 11
16.03.2014 14
... ...
30.03.2018 18

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Danil, 2018-04-21
@DanilBaibak

As an option:

def get_mean(row):
    return np.mean(df[(df['month'] == row[index_for_month_col]) & (df['year'] == row[index_for_year_col])]['Температура'])

df[df['Температура'].isnull()].apply(get_mean, axis=1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question