I have a DataFrame like this.
>>> df = pd.DataFrame([[3., 0, 0], [0, 3., 0], [0, 0, 0], [0, 6., 6.], [1., 0, 0], [2., 5., 0]]).T
>>> df
0 1 2 3 4 5
0 3.0 0.0 0.0 0.0 1.0 2.0
1 0.0 3.0 0.0 6.0 0.0 5.0
2 0.0 0.0 0.0 6.0 0.0 0.0
What I want to do is to keep the first element, column by column, replacing other non-zero values with a zero.
>>> expected
0 1 2 3 4 5
0 3.0 0.0 0.0 0.0 1.0 2.0
1 0.0 3.0 0.0 6.0 0.0 0.0
2 0.0 0.0 0.0 0.0 0.0 0.0
My goal is to get a Series of the first elements, and I thought doing this via sum()
, so I need zero values for other elements in column.
>>> expected.sum()
0 3.0
1 3.0
2 0.0
3 6.0
4 1.0
5 2.0
dtype: float64
Thank you very much in advance.