replace NAs in once column ods file in Python

65 views Asked by At

In an ods file I want to replace empty cells in one column with a string (for example "good"), but when I use the code underneath, it does not work. The empty cells stay empty. The code runs, but it does not change anything.

Import ezodf
import pandas

#read odds bestand
doc = ezodf.opendoc("weather_types")
sheet = doc.sheets["sunshine"]

#read from sheet into pandas dataframe
data = []
for row in tabblad.rows():
    data.append([cell.value for cell in row])
dataset = pd.DataFrame(data[18:],columns = data[17])
   
#replace values in specific column with value "good"
dataset["weather"].fillna("good",inplace = True)

#write the values back to sheet
for i, row in enumerate(dataset.values,start = 18):
    for j, value in enumerate(row):
      if value is None:
        value = "good"
        tabblad[i, j].set_value(value)

#save ods file
doc.save()
0

There are 0 answers