Running Python 3.8.1, 64 bit, on Windows 10.
I have a csv file with two columns. The first column does not have numeric values on every row (=empty cells in between cells with values) and second has numeric values on every row.
column_1 column_2
200
13 201
202
203
204
205
129 206
16 207
208
I read the csv file (shown above) with Pandas:
df = pd.read_csv("old.csv")
I make modifications to the Pandas dataframe and write to a new csv file with Pandas without the index column.
df.to_csv("new.csv", sep=',', encoding='utf-8', index=False)
The result is a csv file that has zeros in place of the original empty cells.
column_1,column_2
0,200
13,201
0,202
0,203
0,204
0,205
129,206
16,207
0,208
My question: how to modify my script to write empty cells instead of zeros (0) in the csv file (i.e. the rows where column_2 value is 200, 202, 203, 204, 205 and 208)?
I make modifications to the Pandas dataframedo you replace missing values to0? Because pandas write only0if exist, if missing values write no value (so get for last value,208)