How to do join including nulls in pyspark?

Viewed 36
I have two data frames

first data frame has 8 columns - col1,col2,col3,col4.col5,col6,col7,col8

second data frame has 10 columns - t_col1,tcol_2,t_col3,t_col4,t_col5,t_col6,t_col7,t_col8,answer_1,answer_2

I am trying for a new merged data frame - that has all the columns from the first data frame and the last two columns from the second dataframe.

The code I used is:

res = res.join(df2, 
            (res.col_1== df2.t_col1) &  
            (res.col_2== df2.t_col2) &
            (res.col_3== df2.t_col3) &
            (res.col_4 == df2_t_col4) &
            (res.col_5== df2.t_col5) &
            (res.col_6== df2.t_col6) &
            (res.col_7== df2.t_col7) &
            (res.col_8== df2.t_col8),
            how='left')

But somehow the null values are getting ignored in the merged data frame. Also, I am getting many NaNs

The result data frame should have cols - col1,col2,col3,col4,col5,col6,col7,col8,answer_1,answer_2

0 Answers
Related