I have a file where multiple values are null, i need to change the values only where values are present and keep null values. Below is what i am trying but it is changing Null values (?) also. Please suggest what can be done.
Input File
A B C
XC123 CXW12 3.43
XC123 ? 11.44
CQ123 AB123 21.23
XC781 ? 44.22
SC568 AB123 2.12
SC568 ? 32.43
DC743 CXW12 324.78
XC123 ? -6432.93
Expected Output File:
A B C
A0 B0 3.43
A0 11.44
A1 B1 21.23
A2 44.22
A3 B1 2.12
A3 32.43
A4 B0 324.78
A0 -6432.93
Code:
df=pd.read_csv('file.csv')
df_mask=pd.DataFrame({
'A':['A{}'.format(i) for i in list(pd.factorize(df['A'])[0])],
'B':['B{}'.format(i) for i in list(pd.factorize(df['B'])[0])],
'C':df['C'].values.tolist(),
})
df_mask.to_csv(finalOutput, sep=',', index=False)