Imposed order on pandas dataframe

The Travis CI test on Python 3.5 kept reordering the dataframe so that the results wouldn't match.
For that reason, I had to impose the order of the columns with a clunky process:
-drop the column of surfaces from whatever location it's in
-reinsert the column of surfaces where I want it to be
This commit is contained in:
Miriam 2020-07-20 00:54:20 +00:00
parent 979317f614
commit 4aa478f17b

View file

@ -6239,14 +6239,17 @@ class SurfaceMGXS(MGXS):
df = df[df['group out'].isin(groups)]
mesh_str = 'mesh {0}'.format(self.domain.id)
surfaces = df[(mesh_str,'surf')]
df.drop(columns=[(mesh_str,'surf')],inplace=True)
df.insert(len(self.domain.dimension),(mesh_str,'surf'),surfaces)
if len(self.domain.dimension) == 1:
df.sort_values(by=[(mesh_str, 'x'), (mesh_str, 'surf')]
+ columns, inplace=True)
elif len(self.domain.dimension) == 2:
df.sort_values(by=[(mesh_str, 'x'), (mesh_str, 'y'),
df.sort_values(by=[(mesh_str, 'x'), (mesh_str, 'y'),
(mesh_str, 'surf')] + columns, inplace=True)
elif len(self.domain.dimension) == 3:
df.sort_values(by=[(mesh_str, 'x'), (mesh_str, 'y'),
df.sort_values(by=[(mesh_str, 'x'), (mesh_str, 'y'),
(mesh_str, 'z'), (mesh_str, 'surf')] + columns, inplace=True)
return df