Skip to content

Instantly share code, notes, and snippets.

@dmd
Created June 4, 2024 12:51
Show Gist options
  • Save dmd/6052208e4c94d863220ed15f3ee58267 to your computer and use it in GitHub Desktop.
Save dmd/6052208e4c94d863220ed15f3ee58267 to your computer and use it in GitHub Desktop.
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.api as sm
# Load the data
file_path = 'output.csv'
data = pd.read_csv(file_path)
# Convert the 'Date' column to datetime format
data['Date'] = pd.to_datetime(data['Date'])
# Sort the data by datetime
data = data.sort_values('Date')
# Reset the index and ensure the 'Date' column is properly formatted
data.reset_index(inplace=True, drop=True)
# Perform LOESS smoothing
loess = sm.nonparametric.lowess
smoothed_values = loess(data['CPM Values'], data['Date'], frac=0.1) # Adjust frac to control the degree of smoothing
# Plot the smoothed data with the specified style
plt.figure(figsize=(12, 6))
plt.scatter(data['Date'], data['CPM Values'], label='Original Data', color='lightgray', s=10)
plt.plot(data['Date'], smoothed_values[:, 1], label='LOESS Smoothed', color='blue', linewidth=2)
plt.title('LOESS Smoothed uSv/h over Time')
plt.xlabel('Datetime')
plt.ylabel('uSv/h')
plt.legend()
plt.grid(True)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment