python - Name Error when getting variable from another define function to be read in another define function in python3 -
i'm not sure how solve problem have encountered, how solve this?
my python code i'm using:
import plotly import plotly.plotly py import plotly.graph_objs go import plotly.figure_factory ff import numpy np datetime import date,time,datetime import pandas pd %matplotlib inline import matplotlib.pyplot plt def readcsv(x): #def function read csv files based on input below data = pd.read_csv(x, parse_dates=['time_stamp'], infer_datetime_format=true) data['date'] = data.time_stamp.dt.date data['time'] = data.time_stamp.dt.time data['time_stamp'] = pd.to_datetime(data['time_stamp']) print(data[1:6]) readcsv('maind.csv') def seltimestamprange(dtstart, dtend, data): timestamprange = (data['time_stamp'] > dtstart) & (data['time_stamp'] <= dtend) timerange = data.loc(timestamprange) timerange.plot(x='time_stamp', y='ac_input_current', style='-', color='black') date_string_start = '2017-06-13 16:00:00' date_string_end = '2017-06-13 16:40:00' dtstart = datetime.strptime(date_string_start, '%y-%m-%d %h:%m:%s') dtend = datetime.strptime(date_string_end,'%y-%m-%d %h:%m:%s') seltimestamprange(dtstart, dtend, data)
my error:
nameerror traceback (most recent call last) in () 10 #print(type(dtstart)) <-- check if dtstart has been converted datetime type 11 ---> 12 seltimestamprange(dtstart, dtend, data)
nameerror: name 'data' not defined
the data
local variable available in function readcsv(x)
, return in function , assign result variable data
, can use variable data
. this:
def readcsv(x): #def function read csv files based on input below data = pd.read_csv(x, parse_dates=['time_stamp'], infer_datetime_format=true) data['date'] = data.time_stamp.dt.date data['time'] = data.time_stamp.dt.time data['time_stamp'] = pd.to_datetime(data['time_stamp']) print(data[1:6]) return data data = readcsv('maind.csv')
Comments
Post a Comment