Skip to content

Instantly share code, notes, and snippets.

@parulnith

parulnith/timeseries.py

Last active Feb 6, 2020
Embed
What would you like to do?
time_series = df.groupBy(F.year('datetime').alias('year'),
F.weekofyear('datetime').alias('week')) \
.agg(rf_agg_mean('ndvi').alias('mean_ndvi'))
ts_pd = time_series.toPandas()
#Visualizing using matplotlib
ts_pd.sort_values(['year', 'week'], inplace=True)
# Create a compact label of year and week number yyyy_ww
ts_pd['year_week'] = ts_pd.apply(lambda r:'{0:g}_{1:02g}'.format(r.year, r.week), axis=1)
plt.figure(figsize=(10,8))
plt.plot(ts_pd.year_week, ts_pd.mean_ndvi, 'g*-', )
xt = plt.xticks(rotation=-45, )
plt.ylabel('NDVI')
plt.xlabel('Year and week')
plt.title('Sunderbans NDVI')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment