date - why do I keep getting the same answer with this conditional, python pandas -
this might dumb problem i've been stuck on awhile.
here's csv
date,time,open,high,low,close,volume 02/03/1997,09:30:00,3045.00,3045.00,3045.00,3045.00,28 02/04/1997,09:30:00,3077.00,3078.00,3077.00,3077.50,280 02/05/1997,09:30:00,3094.00,3094.50,3094.00,3094.00,50 02/06/1997,09:30:00,3106.00,3107.50,3106.00,3107.50,53 02/07/1997,09:30:00,3144.00,3144.00,3143.50,3143.50,15 02/06/1997,16:20:00,3126.50,3126.50,3126.00,3126.00,24 02/06/1997,16:21:00,3126.50,3128.00,3126.50,3128.00,169 02/06/1997,16:22:00,3128.00,3128.00,3126.00,3126.00,243 02/06/1997,16:23:00,3125.50,3126.50,3125.50,3125.50,26
this example made original cause original long. moved "09:30:00" top make easier.
but here's code.
df = pd.read_csv('example.txt', parse_dates = [["date", "time"]], index_col=0) b930 = df.high.at_time("09:30:00") a=0 if 'b930 < 3044.00': = 7 else: = 10 print
if run way 7 shouldn't be.
a=0 if 'b930 > 3044.00': = 7 else: = 10 print
and if run way 7 good.
i've tried bunch of other things erase them.
you works series, have use all
or any
:
b930 = df.high.at_time("09:30:00") print b930 date_time 1997-02-03 09:30:00 3045.0 1997-02-04 09:30:00 3078.0 1997-02-05 09:30:00 3094.5 1997-02-06 09:30:00 3107.5 1997-02-07 09:30:00 3144.0 #valueerror: truth value of series ambiguous. # use a.empty, a.bool(), a.item(), a.any() or a.all(). if b930 < 3044.00: = 7 else: = 10 print
check if all
values true
:
print b930 < 3046.00 date_time 1997-02-03 09:30:00 true 1997-02-04 09:30:00 false 1997-02-05 09:30:00 false 1997-02-06 09:30:00 false 1997-02-07 09:30:00 false name: high, dtype: bool a=0 if (b930 < 3046.00).all(): = 7 else: = 10 print 10
check if any
values true
:
if (b930 < 3046.00).any(): = 7 else: = 10 print 7
another example:
print b930 > 3044.00 date_time 1997-02-03 09:30:00 true 1997-02-04 09:30:00 true 1997-02-05 09:30:00 true 1997-02-06 09:30:00 true 1997-02-07 09:30:00 true name: high, dtype: bool
a=0 if (b930 > 3044.00).all(): = 7 else: = 10 print 7 if (b930 > 3044.00).any(): = 7 else: = 10 print 7
Comments
Post a Comment