Use np.NaN
if need missing value:
import numpy as np
import pandas as pd
df = {'id': [1, 2, 3, 4, 5],
'created_at': ['2020-02-01', '2020-02-02', '2020-02-02', '2020-02-02', '2020-02-03'],
'type': ['red', np.NaN, 'blue', 'blue', 'yellow']}
Or float('NaN')
working too:
df = {'id': [1, 2, 3, 4, 5],
'created_at': ['2020-02-01', '2020-02-02', '2020-02-02', '2020-02-02', '2020-02-03'],
'type': ['red', float('NaN'), 'blue', 'blue', 'yellow']}
df = pd.DataFrame (df, columns = ['id', 'created_at','type', 'converted_tf'])
print (df)
id created_at type converted_tf
0 1 2020-02-01 red NaN
1 2 2020-02-02 NaN NaN
2 3 2020-02-02 blue NaN
3 4 2020-02-02 blue NaN
4 5 2020-02-03 yellow NaN
Or use None
, it most time working same like np.NaN
if processing data in pandas:
df = {'id': [1, 2, 3, 4, 5],
'created_at': ['2020-02-01', '2020-02-02', '2020-02-02', '2020-02-02', '2020-02-03'],
'type': ['red', None, 'blue', 'blue', 'yellow']}
df = pd.DataFrame (df, columns = ['id', 'created_at','type', 'converted_tf'])
print (df)
id created_at type converted_tf
0 1 2020-02-01 red NaN
1 2 2020-02-02 None NaN
2 3 2020-02-02 blue NaN
3 4 2020-02-02 blue NaN
4 5 2020-02-03 yellow NaN