Question: Basically, I have a *dataframe* which has 2 columns, both of which are hours:

```
    0    1
 +-----+----+    
0|  11 | 12 |
 +-----+----+
1|   3 | 4  |
 +-----+----+
2|  11 | 12 |
 +-----+----+
3|   6 |  7 |
 +-----+----+
4|  16 | 16 |

     etc...

```

This has a few thousand rows. I want to make another dataframe which has column headers '1' to '24' (based on the hours of a 24 hour period) and for each row of the dataframe above displays 1 if the hour time is within that range (inclusive) and 0 if it is outside.

So for example the second row of the above dataframe would be something like:

```
1   2   3   4   5   6   7   8 ......24
0   0   1   1   0   0   0   0 ......0

```

And I want to do the same for each row of the first dataframe and append to the new 24 hour data frame.

Hopefully this makes sense and someone can help! Happy to walk through further if it doesn't make sense! Also am new to posting on here so not sure exactly how to get the data to paste over in a sensible way.

Answer: 
You can compare and multiply the values by creating a dataframe i.e 

```
temp = pd.DataFrame([np.arange(1,25)],index = df.index,)

begin = (temp.values>=df['0'].values[:,None]).astype(int)
end = (temp.values<=df['1'].values[:,None]).astype(int)

pd.DataFrame(begin*end,columns=np.arange(1,25))

    1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19  20  21  22  23  24
0   0   0   0   0   0   0   0   0   0   0   1   1   0   0   0   0   0   0   0   0   0   0   0   0
1   0   0   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
2   0   0   0   0   0   0   0   0   0   0   1   1   0   0   0   0   0   0   0   0   0   0   0   0
3   0   0   0   0   0   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
4   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0

```
This is another possible solution:

```
import pandas as pd
df=pd.DataFrame([[11, 12],[3,   4],[11,  12],[6,  7],[16,  16]], columns=[0,1])
print("df= \n ",df)

dg=pd.DataFrame(columns=np.arange(1,26))
for i in df.index:
    for j in [0,1]:
        dg.loc[i,df.iloc[i,j]]=1
print("dg= \n", dg.fillna(0))

df= 
      0   1
0  11  12
1   3   4
2  11  12
3   6   7
4  16  16
dg= 
    1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25
0   0   0   0   0   0   0   0   0   0   0   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0
1   0   0   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
2   0   0   0   0   0   0   0   0   0   0   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0
3   0   0   0   0   0   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
4   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0

```