I have an series object that contains multiple series (341 in this case):
I need to select only first element of each series. For example if I have series:
0 68 -0.22
86 2.54
1 73 -0.10
88 0.57
2 74 -2.18
89 -0.10
I need to get something that would look like this:
0 68 -0.22
1 73 -0.10
2 74 -2.18
and so on.
For empty series I need to ger series number and Nan,or 0:
336 0 0
337 0 0
Thanks a lot!
CodePudding user response:
What you want is unclear. Maybe you can try:
out = pd.concat({x.name: x.iloc[[0]] if not x.empty
else pd.Series(0) for x in sr})
print(out)
# Output
0 68 -0.22
1 73 -0.10
2 74 -2.18
341 0 0.00
dtype: float64