1
$\begingroup$

if I execute the following lines of codes in R as well as python for groupby command, the order of the resulting dataframes are not matching when I convert them to dataframes after that. How to maintain the order to be same when I execute the R code in Python.

in R
project_list <- project_data %>%
  group_by(entity)%>%
  distinct(Manager)
############
Python
project_list=project_data.groupby('entity').Manager.unique()
project_list=pd.DataFrame(project_list)
project_list=project_list.reset_index()
project_list['Manager']=project_list['Manager'].str.get(0)
#############
in R                in Python
entity   Manager  entity   Manager    
ML_10     A        ML_25     D
ML_08     B        ML_10     A
ML_25     D        ML_08     B
But the expected results should be similar to the one from R

What change need to be done in Python code to get the same results?

$\endgroup$
1
  • $\begingroup$ this is normal since there's not constraint on the order of the dataframe returned by group_by. You can just sort the output afterwards any way you like, that will give you a unique order. $\endgroup$ – Erwan Aug 4 '20 at 14:03

Browse other questions tagged or ask your own question.