remove_nan_df

hydrostats.data.remove_nan_df(merged_dataframe)

Drops rows with NaN, zero, negative, and inf values from a pandas dataframe

Parameters:merged_dataframe (DataFrame) – A pandas DataFrame with a datetime index and columns containing float type values.
Returns:Pandas dataframe with rows containing NaN, zero, negative, and inf values removed.
Return type:DataFrame

Examples

>>> import pandas as pd
>>> import numpy as np
>>> import hydrostats.data as hd

An example dataframe is created with invalid values inserted into it.

>>> data = np.random.rand(15, 2)
>>> data[0, 0] = data[1, 1] = np.nan
>>> data[2, 0] = data[3, 1] = np.inf
>>> data[4, 0] = data[5, 1] = 0
>>> data[6, 0] = data[7, 1] = -0.1
>>> example_df = pd.DataFrame(data=data, index=pd.date_range('1980-01-01', periods=15))
>>> example_df
                   0         1
1980-01-01       NaN  0.358903
1980-01-02  0.074718       NaN
1980-01-03       inf  0.515931
1980-01-04  0.498002       inf
1980-01-05  0.000000  0.617974
1980-01-06  0.522522  0.000000
1980-01-07 -0.100000  0.116625
1980-01-08  0.588054 -0.100000
1980-01-09  0.691136  0.561178
1980-01-10  0.998170  0.432411
1980-01-11  0.424473  0.599110
1980-01-12  0.330988  0.469158
1980-01-13  0.633894  0.191701
1980-01-14  0.183241  0.784494
1980-01-15  0.681419  0.303280

Now the NaN, inf, negative, and zero values can be remove with this function.

>>> hd.remove_nan_df(example_df)
                   0         1
1980-01-09  0.691136  0.561178
1980-01-10  0.998170  0.432411
1980-01-11  0.424473  0.599110
1980-01-12  0.330988  0.469158
1980-01-13  0.633894  0.191701
1980-01-14  0.183241  0.784494
1980-01-15  0.681419  0.303280