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

Slicing arrays inside pd dataframe cells

I have a dataframe looking like this:

                                            spectrum  concentration
0  [-0.7966700525900023, 1.051812899165725, -3.22...          97.21
1  [4.2516158928053756, 4.311297642065483, 0.5998...           9.16
2  [2.6277027502790133, 7.421702513385412, -7.280...         184.42
3  [-9.030692948962951, -11.021414125284082, -3.8...          77.61
4  [-7.057630112337506, -4.877704649740394, -10.8...         109.02

and need to select the range [70:920] of each of the arrays in the spectrum collumn.
I tried the following:

df.spectrum.apply(lambda x: x[70:920])

but it didn’t work. Any idea how to do it?

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

>Solution :

I would normally use .map() for this, e.g.,

df.spectrum.map(lambda x: x[70:920])
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