Python programming, with examples in hydraulic engineering and in hydrology.
Wednesday, February 28, 2018
Installing Python in Windows
WinPython is a free open-source portable distribution of the Python programming language for Windows 7/8/10 and scientific and educational usage.
Designed for scientists, data-scientists, and education.
WinPython is a portable application, so the user should not expect any integration into Windows explorer during installation. However, the WinPython Control Panel allows to "register" your distribution to Windows.
Free Download at:
Thursday, February 8, 2018
Daily precipitation data to monthly and yearly
With pandas, we can group datetime values according to datetime units, as months and years.
If we have a pandas dataframe with 2 columns - DATE and VALUE
Certify that the column DATE is recognized as datetime64 format - you can use, for example:
df1['DATE'] = pd.to_datetime(df1['DATE'])
and then you can group and make operations on this group.
Getting the average of total monthly precipitation:
monthly = df1.groupby(df1['DATE'].dt.month).sum() / len(pd.unique(df1['DATE'].dt.year))
(groups by month sum and then divide by the number of years)
Getting the average yearly precipitation:
PAnual = df1.groupby(df1[0].dt.year).sum().mean()
If we have a pandas dataframe with 2 columns - DATE and VALUE
Certify that the column DATE is recognized as datetime64 format - you can use, for example:
df1['DATE'] = pd.to_datetime(df1['DATE'])
and then you can group and make operations on this group.
Getting the average of total monthly precipitation:
monthly = df1.groupby(df1['DATE'].dt.month).sum() / len(pd.unique(df1['DATE'].dt.year))
(groups by month sum and then divide by the number of years)
Getting the average yearly precipitation:
PAnual = df1.groupby(df1[0].dt.year).sum().mean()
Subscribe to:
Posts (Atom)