Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23305

Ratio between columns with nan values. How to choose the column, for each row, without nan values in pandas?

$
0
0

I have the following DF:

z = pd.DataFrame({2016:[4.0,np.nan,6.0,7.0,np.nan],2017:[np.nan,0,5.0,0,np.nan],2018:[4.0,3,np.nan,3,1.0],2019:[2.0,np.nan,np.nan,np.nan,3.4],'ratio':''})

I need a column named 'ratio' to store the ratio between the first year (without nan values) and last year (without nan values) for each row.

For example, for first row it would be 2016/2019, for the second, 2017/2018, for the third, 2016/2017 and so on.

I couldn't figure out how to solve this....


Viewing all articles
Browse latest Browse all 23305

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>