Skip to content

Instantly share code, notes, and snippets.

@marcopeix
Created August 6, 2019 18:39
Show Gist options
  • Save marcopeix/5670571f5e92012fd36fdd5d85478d87 to your computer and use it in GitHub Desktop.
Save marcopeix/5670571f5e92012fd36fdd5d85478d87 to your computer and use it in GitHub Desktop.
# Make dates actual dates
data['Date'] = pd.to_datetime(data['Date'])
# Convert measurements to floats
for col in data.iloc[:,2:].columns:
if data[col].dtypes == object:
data[col] = data[col].str.replace(',', '.').astype('float')
# Compute the average considering only the positive values
def positive_average(num):
return num[num > -200].mean()
# Aggregate data
daily_data = data.drop('Time', axis=1).groupby('Date').apply(positive_average)
# Drop columns with more than 8 NaN
daily_data = daily_data.iloc[:,(daily_data.isna().sum() <= 8).values]
# Remove rows containing NaN values
daily_data = daily_data.dropna()
# Aggregate data by week
weekly_data = daily_data.resample('W').mean()
# Plot the weekly concentration of each gas
def plot_data(col):
plt.figure(figsize=(17, 8))
plt.plot(weekly_data[col])
plt.xlabel('Time')
plt.ylabel(col)
plt.grid(False)
plt.show()
for col in weekly_data.columns:
plot_data(col)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment