How can I use fillna() to fill up empty cells of one file by values from another file?

Viewed 10

I have a dataset with some empty cells in column 'A'. I have another file from a column (say column name 'P') of which I want to fill up the empty cells of column 'A'.

I tried with the below code but it's not working.

import pandas as pd
import numpy as np

df = pd.read_excel('Test Data.xlsx') #This is the file where empty cells are there in column 'A'

a = []

df2 = pd.read_excel('Filler.xlsx') #This is the file where data available in column 'P' to fill up the empty cells 

p = (df2['P'])


for i in p:
    a.append(i)
    

fill = pd.DataFrame(index =df.index[df.isnull().any(axis=1)], data= a,columns=[0])
df.fillna(fill)
0 Answers
Related