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

Replace all cells with "-1" in DataFrame

I have a dataframe like so:

               RANK      COUNT
'2020-01-01'    100         -1
'2020-01-02'     50         -1
'2020-01-03'     -1         75

How can I replace all occurrences of -1 with None and still preserve both the RANK and COUNT as ints?

The result should look like:

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

               RANK      COUNT
'2020-01-01'    100          
'2020-01-02'     50           
'2020-01-03'                75

If this isn’t possible, how can I dump the original data into a .csv file that looks like the desired result?

>Solution :

using replace, replace -1 with ""

out = df.replace(-1, "")
                RANK    COUNT
'2020-01-01'    100     
'2020-01-02'    50  
'2020-01-03'              75
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