Feb-01-2019, 01:23 PM
When I run this script everything works great.
When I change line glucose.append(row.scan) to glucose.append(row.hist)
I get the error: TypeError: float() argument must be a string or a number, not 'method'
I am pretty sure it has to be something with df.loc[df['hist'] == 0, 'hist'] = df['scan'], but not sure what.
When I change line glucose.append(row.scan) to glucose.append(row.hist)
I get the error: TypeError: float() argument must be a string or a number, not 'method'
I am pretty sure it has to be something with df.loc[df['hist'] == 0, 'hist'] = df['scan'], but not sure what.
import pandas as pd import numpy as np import matplotlib.pyplot as plt import datetime # --------------------------------- read from csv --------------------------- df = pd.read_csv('summary.csv', delimiter='\t', skiprows=3, header=None, names=[ 'id', 'rdate', 'rtype', 'hist', 'scan'], usecols=[0, 1, 2, 3, 4]) # ---------- Fill in 0 --------------------------- df['hist'] = df['hist'].fillna(0) df['scan'] = df['scan'].fillna(0) # -------------- Change dtypes ------------------- df['rdate'] = df['rdate'].astype('datetime64') df['hist'] = df['hist'].astype('int64') df['scan'] = df['scan'].astype('int64') df.loc[df['hist'] == 0, 'hist'] = df['scan'] sd = (df[df.rtype == 1]) sr = (sd[sd.rdate >= datetime.datetime.now() - pd.to_timedelta("2day")]) def displayplot(time, glucose): fig, ax = plt.subplots() plt.plot(time, glucose, color='k', marker='o', label='Glucose', linewidth=1, markevery=1, markerfacecolor='blue') plt.plot(time, glucose) ax.grid() ax.tick_params(axis='y') fig.autofmt_xdate() plt.axhspan(80, 120, facecolor='lightgreen', alpha=0.5) # plt.axhline(y=80, color='green') plt.axhline(y=180, color='red') plt.axhline(y=70, color='red') plt.title('Daily Glucose Chart') plt.ylabel('Glucose') plt.xlabel('Time') plt.legend(loc=2) plt.yticks(np.arange(0, 360, 10.0)) plt.tight_layout() plt.show() # --------------------------------------------------------------------------------------------------------- time = [] glucose = [] for i, row in sr.iterrows(): time.append(row.rdate) [b]glucose.append(row.scan)[/b] displayplot(time, glucose)Thanks for the help.