Suppose I initialize an 'empty' DataFrame as follows:
import pandas as pd
import numpy as np
df = pd.DataFrame(index=list('AB'), columns=list('CD'))
The resulting df
has the form
C D
A NaN NaN
B NaN NaN
Is there a pythonic way to replace the NaN
s with some other value, say, -np.inf
? Of course, one way to do it is simply to specify it as data:
df = pd.DataFrame(data=np.ones((2,2))*(-np.inf), index=list('AB'), columns=list('CD'))
Perhaps there a more succinct way?