This problem contains 3 separate dataframes. df1 represents the 'Total' of products 1,2,3, containing 'value1', 'value2' df2 represents the 'Customer1' of products 1,2,3, containing 'value1', 'value2' df3 represents the 'Customer2' of products 1,2,3, containing 'value1', 'value2'
df2 & df3 are essentially subsets of df1.
I would like to create another dataframe that subtracts df2&df3 from df1 and label this df4. I want df4 to be 'remaining customers' within the 'Market' Column.
This is what I have done so far
import pandas as pd
d1 = {'Market': ['Total', 'Total','Total'], 'Product Code': [1, 2, 3],
'Value1':[10, 20, 30], 'Value2':[5, 15, 25]}
df1 = pd.DataFrame(data=d1)
df1
d2 = {'Market': ['Customer1', 'Customer1','Customer1'], 'Product Code': [1,
2, 3], 'Value1':[3, 14, 10], 'Value2':[2, 4, 6]}
df2 = pd.DataFrame(data=d2)
df2
d3 = {'Market': ['Customer2', 'Customer2','Customer2'], 'Product Code': [1,
2, 3], 'Value1':[3, 3, 4], 'Value2':[2, 6, 10]}
df3 = pd.DataFrame(data=d3)
df3
This produces the following result..
Market Product Code Value1 Value2
0 Total 1 10 5
1 Total 2 20 15
2 Total 3 30 25
Market Product Code Value1 Value2
0 Customer1 1 3 2
1 Customer1 2 14 4
2 Customer1 3 10 6
Market Product Code Value1 Value2
0 Customer2 1 3 2
1 Customer2 2 3 6
2 Customer2 3 4 10
To create df4, I try the following code and get an error 'TypeError: unsupported operand type(s) for -: 'str' and 'str'' Can anyone help?
df4 = df1-(df2+df3)
print(df4)