What's the best way to get a pandas dataframe with two columns that provide all possible combinations of numbers in two lists?
I've used itertools to get a list of lists with the combinations, but can't work out how to get it into a dataframe
Here's what I've tried
import itertools
import pandas as pd
income_range = np.linspace(1,3,3)
costs_range = np.linspace(1, 3, 3)
all_combinations = [list(zip(each_permutation, costs_range)) for each_permutation in itertools.permutations(income_range, len(costs_range))]
df = pd.DataFrame(all_combinations)
This is the output that I get
| | 0 | 1 | 2 |
|---:|:-----------|:-----------|:-----------|
| 0 | (1.0, 1.0) | (2.0, 2.0) | (3.0, 3.0) |
| 1 | (1.0, 1.0) | (3.0, 2.0) | (2.0, 3.0) |
| 2 | (2.0, 1.0) | (1.0, 2.0) | (3.0, 3.0) |
| 3 | (2.0, 1.0) | (3.0, 2.0) | (1.0, 3.0) |
| 4 | (3.0, 1.0) | (1.0, 2.0) | (2.0, 3.0) |
| 5 | (3.0, 1.0) | (2.0, 2.0) | (1.0, 3.0) |
This is the output that I want
| Income | Costs |
| ------ | ----- |
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 2 |
| 2 | 3 |
| 3 | 1 |
| 3 | 2 |
| 3 | 3 |