How do I add 1 into a column of numbers and replace null value with 1 as well in python

18 views Asked by At
out_df['# of Days'] = out_df['# of Days'].replace('',1)
out_df['# of Days'] += 1

print(out_df)

Would work except when cell's have NULL as their value, it does not add the 1 value.

Trying to add 1 to the entire column including empty cell in the column.

1

There are 1 answers

1
WestMountain On
def newValue(value):
    if value == "":
        return 1
    if value is None:
        return 1
    return value + 1

out_df['# of Days'] = newValue(out_df['# of Days'])