Skip to content

Commit a408f0a

Browse files
committed
Possibility to remove all NaNs features or not after featurization.
1 parent e8d0c8e commit a408f0a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

modnet/featurizers/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
__all__ = ("clean_df",)
44

55

6-
def clean_df(df):
6+
def clean_df(df, drop_allnan: bool = True):
77
"""Cleans dataframe by dropping missing values, replacing NaN's and infinities
88
and selecting only columns containing numerical data.
99
1010
Args:
1111
df (pd.DataFrame): the dataframe to clean.
12+
drop_allnan: if True, clean_df will remove features that are fully NaNs.
1213
1314
Returns:
1415
pandas.DataFrame: the cleaned dataframe.
1516
1617
"""
1718

1819
df = df.select_dtypes(include="number")
19-
df = df.dropna(axis=1, how="all")
20+
if drop_allnan:
21+
df = df.dropna(axis=1, how="all")
2022
df = df.replace([np.inf, -np.inf, np.nan], np.nan)
2123

2224
return df

0 commit comments

Comments
 (0)