I have 4 pandas dataframe, First two are Categorical and Numeric Values df,
Cat_data = [
['Color', 'red', 0.2543],
['Color', 'orange',0.1894],
['Color', 'yellow',-0.2836],
['Fruit', 'orange', -1.3647],
['Fruit','banana',0.3648]
]
Cat_df = pd.DataFrame(Cat_data, columns = ['Variable', 'Cats', 'Value'])
Num_data = [
['Quantity', '-inf', '5', 0.2145],
['Quantity', '5', '10', 0.0268],
['Quantity', '10', 'inf', -0.5421],
['Rating', '-inf', '0.5', 0.6521],
['Rating','0.5', 'inf', -0.4378],
]
Num_df = pd.DataFrame(Num_data, columns = ['Variable', 'Inclusive', 'Exclusive', 'Value'])
In the Num_data 'Inclusive' and 'Exclusive' are checking values,
say on the first record >= -inf and < 5 ,
same for second record values >=5 and < 10, values come from Actual_df
Third Dataframe is the actual values
Actual_data = [
['yellow', 'banana', '4', '0.5']
]
Actual_df = pd.DataFrame(Actual_data, columns = ['Color', 'Fruit', 'Quantity', 'Rating'])
Fourth is the Value DataFrame with column names same as Actual_df
Value_df = pandas.DataFrame(numpy.zeros((1, 4)),
columns = ['Color', 'Fruit', 'Quantity', 'Rating'])
I need to fill the Value_df with the 'Value' from Cat_data and Num_data 'Value' columns corresponding to the data in Actual_data, I am not sure how to merge the four df's and take values to check the Inclusive and Exclusive columns along with that.
In Actual Data we have 'yellow', 'banana', '4', '0.5' the value corresponding to
yellow is in Cat_df as -0.2836
banana is in Cat_df as 0.3648
Quantity is in Num_df as 0.2145
Rating is in Num_df as -0.4378
My Result DataFrame of Value_df will be
Color Fruit Quantity Rating
-0.2836 0.3648 0.2145 -0.4378
For the Cat_data, I did like
Value_df['Color'] = Actual_df['Color'].map(Cat_df.set_index('Cats')['Value'])
The issue for the color and fruit both orange, which value will be taken is the problem, so I have to match variable as well, I get error as
InvalidIndexError: Reindexing only valid with uniquely valued Index objects