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

ValueError: could not convert string to float: 'Null' (Pandas)

I’m trying to write the value of a row to "Null" but it doesn’t seem to work. I get the following error: ValueError: could not convert string to float: 'Null'

test.csv:

SIDE,PRICE,QTY,OPEN
BUY,0.25,0.22,True
BUY,0.26,0.23,True
BUY,0.27,0.24,True
BUY,0.28,0.25,True

Code:

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

import pandas as pd
import csv

test_dataframe = pd.read_csv('test.csv')

test_dataframe.at[2, 'OPEN'] = False
test_dataframe.at[2, 'QTY'] = "Null"

test_dataframe.to_csv("test.csv", index=False)

How can I write "Null" to a row because that’s what I want?

>Solution :

Instead of using:

test_dataframe.at[2, 'QTY'] = "Null"

You can use this instead to change the value of any row within any column to "Null"(i.e. In this case I have implemented it to the third row of the third column.

test_dataframe.loc[2, "QTY"] = 'Null'

This code worked well in my case, please do comment if you are facing with any issue:

enter image description here

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