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

Pandas Loc selection to a list of NaN and Values

I want to select some points from a pandas data frame df under a certain condition and then add them to a plot using mplfinance.
Im using the mpf.make_addplot() function. This takes a list in the form of:

signal=[nan, nan, 7, nan, 6, 8, nan]

However selecting values from a pandas df gives a list like so:

df = pd.DataFrame({'column': [1, 2, 7, 0, 6, 8, -9]
pandaslist =  df.loc[ df.column > 5 ]
pandaslist = [7,6,8]

(Ofcourse the pandaslist has an index)
Is there a way to use pandas loc to get a list in form of the signal list?
Is there a way to make mpf to accept input in the style of the pandaslist?

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 :

.loc doesn’t work like that.

Instead, you can use df.where() to select the values you want while nullifying the others.

df.where(df['column'] > 5)
   column
0     NaN
1     NaN
2     7.0
3     NaN
4     6.0
5     8.0
6     NaN
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