Last update: 09.06.2020 13:08:43
# Sample code generated by DasData www.DasData.co import requests import pandas as pd import matplotlib.pyplot as plt plt.style.use('seaborn-whitegrid') import numpy as np %matplotlib inline data_url = 'https://DasData.co/e.aspx?das=1UagCsZOPvpePwr8cqhQ6FmCW7xGxYZX1QMKkO7XYhWjbNOnseOJLMvTNHz7Nvj8Dm8Ed0EiinPzMj1dcTyNag==&from=0&to=500&json=1' response = requests.get(data_url, data={"limit" : "500"}) if response.status_code == 200: df = pd.DataFrame.from_records(response.json()) print(df) #==================================================================== df[['id','AIDate','PatientID','MedicationName','Whenwastaken','MedicationDosage(mg)' ]] = df['Table'].apply(pd.Series) #==================================================================== df["AIDate"] = pd.to_datetime(df["AIDate"]) df.set_index('AIDate', inplace=True) df.head() PatientID=df[['PatientID']] MedicationName=df[['MedicationName']] Whenwastaken=df[['Whenwastaken']] MedicationDosage(mg)=df[['MedicationDosage(mg)']] #==================================================================== df_rm = pd.concat([PatientID.rolling(12).mean(),MedicationName.rolling(12).mean(),Whenwastaken.rolling(12).mean(),MedicationDosage(mg).rolling(12).mean()], axis=1) #==================================================================== df_rm.plot(figsize=(20,10), linewidth=2, fontsize=15) x = np.linspace(0, 10, 50) plt.xlabel('AIDate', fontsize=12);