1. 程式人生 > >Python中給Nan值更改為0

Python中給Nan值更改為0

import pandas as pd
df1 = pd.DataFrame([{'col1':'a', 'col2':1}, {'col1':'b', 'col2':2}])
df2 = pd.DataFrame([{'col1':'a', 'col3':11}, {'col1':'c', 'col3':33}])

data = pd.merge(left=df1, right=df2, how='left', left_on='col1', right_on='col1')
print (data)
# 將NaN替換為0
print (data.fillna(0))