What is a pandoric way to get a value and index of the first non-zero element in each column of a DataFrame (top to bottom)?
import pandas as pd
df = pd.DataFrame([[0, 0, 0],
[0, 10, 0],
[4, 0, 0],
[1, 2, 3]],
columns=['first', 'second', 'third'])
print(df.head())
# first second third
# 0 0 0 0
# 1 0 10 0
# 2 4 0 0
# 3 1 2 3
What I would like to achieve:
# value pos
# first 4 2
# second 10 1
# third 1 3