I have a dataframe like this:
Date Shift Machine_number production
9/1/2016 C 1 0.795578112
9/1/2016 C 2 0.40730688
9/1/2016 C 3 0.41150592
9/1/2016 C 4 0.40310784
9/1/2016 C 5 0.376233984
9/2/2016 A 1 0.470486495
9/2/2016 A 2 0.41360544
9/2/2016 A 3 0.41780448
9/2/2016 A 4 0.40520736
9/2/2016 A 5 0.329204736
9/2/2016 B 1 0.472911683
9/2/2016 B 2 0.4094064
9/2/2016 B 3 0.4094064
9/2/2016 B 4 0.41570496
9/2/2016 B 5 0.366436224
I want to create a dataframe with multiple index as:
Date Machine No. Shift production
9/1/2016 1 c 0.795578112
9/2/2016 1 a 0.470486495
9/2/2016 1 b 0.472911683
Thanks.
I tried:
idx0=np.array(df['Machine_number'])
idx1 = np.array(df['Shift'])
df2 = DataFrame(index = [idx0,idx1], columns = df["production"])
I think you need
set_index
:First solution with
sort_values
:If need change of order to
C, A, B
useordered Categorical
and set order in parametercategories
: