I am new to Python and trying to store results from a for-loop into dataframe columns (Python 3). Let's say I have the following data:
time=[1,2,3,4]
i=[1,2,3,4,5]
j=[10,20,30,40,50]
k=[100,200,300,400,500]
data_ijk=list(zip(i,j,k))
[(1, 10, 100), (2, 20, 200), (3, 30, 300), (4, 40, 400), (5, 50, 500)]
I want to loop through the data_ijk to solve the following equation:
eq=(i+j+k)*t
and put the results of equation into dataframe with column labels
col_labels=["A","B","C","D","E"] for each set of ijk and rows considering time (t).
The expected output should look something like this:
| t | A | B | C | D | E |
|---|---|---|---|---|---|
| 1 | 111 | 222 | 333 | 444 | 555 |
| 2 | 222 | 444 | 666 | 888 | 1100 |
| 3 | 333 | 666 | 999 | 1332 | 1665 |
| 4 | 444 | 888 | 1332 | 1776 | 2220 |
I know i need to define dataframe
df = pd.DataFrame(columns=[col_labels])
and I assume I should create nested for loop with data_abc and time, but I have no idea how to define to put results in different columns
for i,j,k in data_abc:
for t in time:
...???
print((i+j+k)*t)
timebut 5 in each of the other three lists?