回答編集履歴

2

2023/05/10 03:39

投稿

melian
melian

スコア19840

test CHANGED
@@ -1,6 +1,12 @@
1
1
  ```python
2
+ import pandas as pd
3
+ import numpy as np
4
+
5
+ df = pd.read_csv('data/src/sample_pandas_normal.csv')
6
+
2
- idx = df.select_dtypes(include=['int', 'float']).abs().ge(0.2).any(axis=1)
7
+ idx = df.select_dtypes(include=[np.number]).abs().ge(0.2).any(axis=1)
3
8
  dfx = df[idx].reset_index(drop=True)
9
+
4
10
  print(dfx)
5
11
  ```
6
12
  | name | A | B | C |

1

2023/05/10 02:17

投稿

melian
melian

スコア19840

test CHANGED
@@ -1,7 +1,6 @@
1
1
  ```python
2
- idx = df.select_dtypes(include=['int', 'float']).apply(lambda x: (x<=-0.2)|(x>=0.2)).any(axis=1)
2
+ idx = df.select_dtypes(include=['int', 'float']).abs().ge(0.2).any(axis=1)
3
- dfx = df[idx]
3
+ dfx = df[idx].reset_index(drop=True)
4
-
5
4
  print(dfx)
6
5
  ```
7
6
  | name | A | B | C |