get_the_first_non_null_value_in_each_column
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
get_the_first_non_null_value_in_each_column [2021/09/15 21:57] – [get the first value not equal to a number] raju | get_the_first_non_null_value_in_each_column [2021/09/15 22:02] – [Use case] raju | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Get the first non null value in each column ===== | ===== Get the first non null value in each column ===== | ||
==== Task ==== | ==== Task ==== | ||
- | Get the first non null value in each column | + | Get the first non null value in each column. |
Corner cases: | Corner cases: | ||
Line 66: | Line 66: | ||
==== meta ==== | ==== meta ==== | ||
- | used | Python 3.9.4 and IPython 7.22.0 | + | Used | Python 3.9.4 and IPython 7.22.0 |
demonstrates | apply a function on each column of a dataframe after doing a groupby | demonstrates | apply a function on each column of a dataframe after doing a groupby | ||
Line 72: | Line 72: | ||
===== Get the first value not equal to a number ===== | ===== Get the first value not equal to a number ===== | ||
==== Use case ==== | ==== Use case ==== | ||
- | One downside of using np.nan to denote missing | + | One downside of using np.nan to denote |
dataframe gets " | dataframe gets " | ||
- | A work around is to use a specific integer to denote missing values. For example if we expect | + | One work around is to use a specific integer to denote missing values. For example if we expect |
all integers to be positive, we can use -9999 to denote a missing value. Let's call this | all integers to be positive, we can use -9999 to denote a missing value. Let's call this | ||
- | special integer NAN_INT | + | special integer NAN_INT. |
- | NAN_INT | + | |
==== Task ==== | ==== Task ==== | ||
Line 103: | Line 102: | ||
< | < | ||
$ ipython | $ ipython | ||
- | Python 3.9.4 (default, Apr 9 2021, 11:43:21) [MSC v.1916 64 bit (AMD64)] | ||
- | Type ' | ||
- | IPython 7.22.0 -- An enhanced Interactive Python. Type '?' | ||
In [1]: | In [1]: | ||
Line 155: | Line 151: | ||
1 1 3 4 -9999 | 1 1 3 4 -9999 | ||
</ | </ | ||
+ | ==== meta ==== | ||
+ | Used | Python 3.9.4, IPython 7.22.0 | ||
+ |
get_the_first_non_null_value_in_each_column.txt · Last modified: 2021/09/15 22:03 by raju