回答編集履歴
1
test
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
```python
|
2
2
|
grp = df.loc[:, 'col2':'col4'].apply(lambda x: ~x.str.contains('X').any(), axis=1)
|
3
|
-
df2 = df.groupby(grp, group_keys=False).apply(pd.DataFrame.sort_values, by='col1')
|
3
|
+
df2 = df.groupby(grp, group_keys=False).apply(pd.DataFrame.sort_values, by='col1').reset_index(drop=True)
|
4
4
|
print(df2)
|
5
5
|
```
|
6
6
|
|
7
|
-
| col1 | col2 | col3 | col4 |
|
7
|
+
| | col1 | col2 | col3 | col4 |
|
8
|
-
|:------
|
8
|
+
|---:|:------:|:------:|:------:|:------:|
|
9
|
-
| A | 2 | X | 1 |
|
9
|
+
| 0 | A | 2 | X | 1 |
|
10
|
-
| B | X | 1 | 1 |
|
10
|
+
| 1 | B | X | 1 | 1 |
|
11
|
-
| B | 1 | 1 | X |
|
11
|
+
| 2 | B | 1 | 1 | X |
|
12
|
-
| C | X | 1 | 1 |
|
12
|
+
| 3 | C | X | 1 | 1 |
|
13
|
-
| C | 1 | X | 1 |
|
13
|
+
| 4 | C | 1 | X | 1 |
|
14
|
-
| A | 2 | 1 | 1 |
|
14
|
+
| 5 | A | 2 | 1 | 1 |
|
15
|
-
| C | 6 | 1 | 1 |
|
15
|
+
| 6 | C | 6 | 1 | 1 |
|
16
16
|
|