how to replace null values with 0 in python

Solutions on MaxInterview for how to replace null values with 0 in python by the best coders in the world

showing results for - "how to replace null values with 0 in python"
Matteo
07 Aug 2019
1#Utilise the fillna function from pandas.DataFrame.
2#Note: It will fill na values for every column.
3import pandas as pd
4
5df = pd.DataFrame(dict)
6#or
7df = pd.read_csv("csv_file")
8
9df = df.fillna(0)
10
11#Note: the fillna function comes from the pandas dataframe function.
12#For example:
13
14pd.DataFrame(dict).fillna(int)
15
16#Pandas DataFrame function is also a class because it contains functions
17#of its own.
18
19#The same with read_csv function and
20#other pandas functions that read diffrent file formats.
21