0

I am loading csv files to sql server table. EmpNo Ename ProdID Sales Value Int Varchar Int Int Float

But I am getting ProdID,Sales,Amount Values as 0 for blanks.But want to keep them as blank. I am using this code for keeping nulls. Please help me. Thanks in advance.

df = pd.read_csv(f, header=None,names=file_titles,low_memory=False)
df.columns = df.columns.str.strip()
df = df.fillna(value=' ')

Source Data

EmpNo   Ename   ProdID  Sales   Amount
1   E1      10  120.00
2   E2  1   2   100.00
3   E3          
4   E4  3   3   353.00
5   E5      6   443.00
6   E6  4   8   533.00

Expected Output

EmpNo   Ename   ProdID  Sales   Amount
1   E1  0   10  120.00
2   E2  1   2   100.00
3   E3  0   0   0.00
4   E4  3   3   353.00
5   E5  0   6   443.00
6   E6  4   8   533.00

1 Answer 1

1

Try: df=df.where(df[['Ename','ProdID','Sales']].eq(' '),0)

Sign up to request clarification or add additional context in comments.

3 Comments

I confused. How to load the data as it is like if value is blank. It must must be blank likebelow or same source data.EmpNo Ename ProdID Sales Amount 1 E1 10 120.00 2 E2 1 2 100.00 3 E3 4 E4 3 3 353.00 5 E5 6 443.00 6 E6 4 8 533.00
I confused. How to load source data is it is. if value is blank, it must be blank.Please help me.
what command are you using to import to sql? it could be fail. I need see it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.