This question maybe super basic and apologize for that..
But I am trying to create a for loop that would enter a value of 1 or 0 into a pandas dataframe based on a condition.
import pandas as pd
def checkHour6(time):
val = 0
if time == 6:
val = 1
return val
def checkHour7(time):
val = 0
if time == 7:
val = 1
return val
def checkHour8(time):
val = 0
if time == 8:
val = 1
return val
def checkHour9(time):
val = 0
if time == 9:
val = 1
return val
def checkHour10(time):
val = 0
if time == 10:
val = 1
return val
This for loop that I am attempting will count from 0 to 23, and I am attempting to building pandas dataframe in the loop process that will enter a value of a 1 or 0 appropriately but I am missing something basic as the final df result is an empty dataframe.
Create empty df:
df = pd.DataFrame({'hour_6':[], 'hour_7':[], 'hour_8':[], 'hour_9':[], 'hour_10':[]})
For Loop:
hour = -1
for i in range(24):
stuff = []
hour = hour + 1
stuff.append(checkHour6(hour))
stuff.append(checkHour7(hour))
stuff.append(checkHour8(hour))
stuff.append(checkHour9(hour))
stuff.append(checkHour10(hour))
df.append(stuff)