I have the following pandas DataFrame example. I try to to have sum of some spesific rows. I have researched how to carry out, however I could not find the solution. Could you give a direction, please? The example is as below. I thought that I can apply group by and sum but there is column (Value_3) that I would not like to sum of these, just keeping same. Value 3 is constant value, shaped due to Machine and Shift value.
data = {'Machine':['Mch_1', 'Mch_1', 'Mch_1', 'Mch_1', 'Mch_2', 'Mch_2'], 'Shift':['Day', 'Day', 'Night', 'Night', 'Night', 'Night'], 'Value_1':[1, 2, 0, 0, 1, 3], 'Value_2':[0, 2, 2, 1, 3, 0], 'Value_3':[5, 5, 2, 2, 6, 6]}
df = pd.DataFrame(data)
Output:
Mch_1__Day__1__0__5
Mch_1__Day__2__2__5
Mch_1__Night_0__2__2
Mch_1__Night_0__1__2
Mch_2__Night_1__3__6
Mch_2__Night_3__0__6
What I would like to have is like as showed in dataframe.
expected = {'Machine':['Mch_1', 'Mch_1', 'Mch_2'], 'Shift':['Day', 'Night', 'Night'], 'Value_1':[3, 0, 4], 'Value_2':[2, 3, 3]}
df_expected = pd.DataFrame(expected)
df_expected
Output:
Mch_1__Day__3__2__5
Mch_1__Night_0__3__2
Mch_2__Night_4__3__6
Thank you very much.