data["Gender"].fillna("No Gender", inplace = True)
df.fillna('', inplace=True)
# Try using a loc instead of a where:
df_sub = df.loc[df.yourcolumn == 'yourvalue']
pd.data.replace('?', np.nan)
In [1]: df = DataFrame([[True, True, False],[False, False, True]]).T
In [2]: df
Out[2]:
0 1
0 True False
1 True False
2 False True
In [3]: df.applymap(lambda x: 1 if x else np.nan)
Out[3]:
0 1
0 1 NaN
1 1 NaN
2 NaN 1
df.fillna('()').applymap(ast.literal_eval)
from ast import literal_eval
from io import StringIO
# replicate csv file
x = StringIO("""A,B
,"('t1', 't2')"
"('t3', 't4')",""")
def literal_converter(val):
# replace first val with '' or some other null identifier if required
return val if val == '' else literal_eval(val)
df = pd.read_csv(x, delimiter=',', converters=dict.fromkeys('AB', literal_converter))
print(df)
A B
0 (t1, t2)
1 (t3, t4)