I have two DataFrames:
fuels = pd.DataFrame({'Fuel_Type':['Gasoline', 'Diesel', 'E85']})
years = pd.DataFrame()
years['Year_Model'] = range(2012, 2041)
My desired output is a single new DataFrame which combines these two dataframes as two columns, but for each value in 'years', have it repeated for every unique fuel type in 'fuels'.
In other words, there should be three repetitions for each distinct year, one for each type of fuel.
I can do this very simply in R with:
df <- merge(
data.frame(years = c(2012:2040)),
data.frame(fuels = c("Gasoline", "Diesel", "E85")),
allow.cartesian = T)
I have looked at answers for similar questions such as:
Create all possible combinations of multiple columns in a Pandas DataFrame
Performant cartesian product (CROSS JOIN) with pandas
But, either I cannot seem to apply the answers' code to my own data, or the answers are too complex for me to understand (as I am very new to Python).
Is there a nice and 'easy to understand' way of doing this?