I'm trying to create a dataframe by "multiplying" two others. Let me show you what I've tried to do.
1 - Create a dataframe from a data range
df_dates = pd.DataFrame({'date_prediciton':pd.date_range(start='2021-08-01', end='2021-08-31', freq='W-SUN')})
df_dates.head()
date_prediciton
0 2021-08-01
1 2021-08-08
2 2021-08-15
3 2021-08-22
4 2021-08-29
2 - Create a dataframe of clients
client = ['101', '102', '103', '104']
df_clients = pd.DataFrame(data=client, columns=['client'])
df_clients.head()
client
0 101
1 102
2 103
3 104
3 - Then a need to "multiply" (this may not be the right expression), each client to the date range
You can use pd.MultiIndex.from_product
to create cartesian product of the two:
print (pd.MultiIndex.from_product([client, df_dates["date_prediciton"]]).to_frame(index=0, name=["client", "date"]))
client date
0 101 2021-08-01
1 101 2021-08-08
2 101 2021-08-15
3 101 2021-08-22
4 101 2021-08-29
5 102 2021-08-01
6 102 2021-08-08
7 102 2021-08-15
8 102 2021-08-22
9 102 2021-08-29
10 103 2021-08-01
11 103 2021-08-08
12 103 2021-08-15
13 103 2021-08-22
14 103 2021-08-29
15 104 2021-08-01
16 104 2021-08-08
17 104 2021-08-15
18 104 2021-08-22
19 104 2021-08-29