Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selecting first element of a series

I have an series object that contains multiple series (341 in this case):

enter image description here

I need to select only first element of each series. For example if I have series:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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!

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading