In [26]:
import pandas as pd
import requests
import matplotlib.pyplot as plt
In [27]:
url = "https://stats-service-api-prufung.wma.chs.usgs.gov/statistics/v0/observationNormals?approvalStatus=approved&approvalStatus=provisional&computationType=maximum&computationType=minimum&countryFips=US&mimeType=application%2Fjson&monitoringLocationIdentifier=USGS-01432160&pageSize=1000"
response = requests.get(url)

if response.status_code == 200:
    data = response.json()
else:
    print(f'Error:{response.status_code}')
In [28]:
graphed_data = data['features'][0]['properties']['data'][0]['values']
df = pd.DataFrame(graphed_data)
print(df)
    time_of_year time_of_year_type    value  sample_count approval_status  \
0          02-27       day_of_year   7590.0             6        approved   
1          05-13       day_of_year  14300.0             5        approved   
2          01-19       day_of_year   7720.0             7     provisional   
3          10-08       day_of_year   7720.0             7     provisional   
4          08-01       day_of_year   3090.0             5        approved   
..           ...               ...      ...           ...             ...   
751           11     month_of_year   2395.0             6        approved   
752           12     month_of_year   3030.0             6        approved   
753           04     month_of_year   3895.0             5        approved   
754           05     month_of_year   2800.0             5        approved   
755           10     month_of_year   1450.0             6        approved   

                           computation_id computation  
0    e5e9c007-623f-4c5d-9072-28acf92db855     maximum  
1    c6311bc8-4566-47a4-aa49-dfbd637a1f7d     maximum  
2    4fd5a125-f9ce-4b71-a820-15c2c77664b6     maximum  
3    fda0d26b-a765-42a4-a136-4995dd599847     maximum  
4    e5b95ae0-fbac-41d3-abf6-c2981cd62091     maximum  
..                                    ...         ...  
751  73450be5-3a40-4ab6-af29-079cf1a8002e     minimum  
752  783c75bf-1a76-406c-a598-1719c54863d5     minimum  
753  6848d1e6-ea44-4515-ad79-8b8adb78e7be     minimum  
754  f921a0d7-8599-4f1a-9472-fbabe46db23a     minimum  
755  87d92c5d-3d49-49eb-998c-4c5c1cd1272a     minimum  

[756 rows x 7 columns]
In [29]:
df['value'] = df['value'].astype(float)
max_df = df[df['computation']=='maximum']
min_df = df[df['computation']=='minimum']
In [30]:
# Step 4: Plotting the Maximum Values
plt.figure(figsize=(10, 5))

# Plot for Maximum Values
plt.subplot(1, 2, 1)  # 1 row, 2 columns, 1st subplot
plt.bar(max_df['time_of_year'], max_df['value'], color='blue', alpha=0.7)
plt.title('Maximum Values')
plt.xlabel('Time of Year')
plt.ylabel('Value')

# Plot for Minimum Values
plt.subplot(1, 2, 2)  # 1 row, 2 columns, 2nd subplot
plt.bar(min_df['time_of_year'], min_df['value'], color='red', alpha=0.7)
plt.title('Minimum Values')
plt.xlabel('Time of Year')
plt.ylabel('Value')

plt.tight_layout()
plt.show()
In [ ]: