0

I have 2 dataframes that I'm trying to join. The dataframes have been converted to dataframes from lists. When I join them, all the values of the second dataframe are being displayed as 'NaN'. How & why did the values become null?

I tried join the second dataframe as a column to the first dataframe.

Dataframe 1 (entries_df):

                                0
Country                         0
Year                            0
Status                          0
Life expectancy                 10
Adult Mortality                 10
infant deaths                   0
Alcohol                         194
percentage expenditure          0
Hepatitis B                     553
Measles                         0
BMI                             34
under-five deaths               0
Polio                           19
Total expenditure               226
Diphtheria                      19
HIV/AIDS                        0
GDP                             448
Population                      652
thinness 1-19 years             34
thinness 5-9 years              34
Income composition of resources 167
Schooling                       163

Dataframe 2 (per_df):

    0
0   0.000000
1   0.000000
2   0.000000
3   0.340368
4   0.340368
5   0.000000
6   6.603131
7   0.000000
8   18.822328
9   0.000000
10  1.157250
11  0.000000
12  0.646698
13  7.692308
14  0.646698
15  0.000000
16  15.248468
17  22.191967
18  1.157250
19  1.157250
20  5.684139
21  5.547992

My code:

entries_df= pd.DataFrame(entries)                     #dataframe1
per_df = pd.DataFrame(lst)                            #dataframe2

entries_df['Percentage of missing values']=per_df     
entries_df

Output:

                                0   Percentage of missing values
Country                         0   NaN
Year                            0   NaN
Status                          0   NaN
Life expectancy                 10  NaN
Adult Mortality                 10  NaN
infant deaths                   0   NaN
Alcohol                         194 NaN
percentage expenditure          0   NaN
Hepatitis B                     553 NaN
Measles                         0   NaN
BMI                             34  NaN
under-five deaths               0   NaN
Polio                           19  NaN
Total expenditure               226 NaN
Diphtheria                      19  NaN
HIV/AIDS                        0   NaN
GDP                             448 NaN
Population                      652 NaN
thinness 1-19 years             34  NaN
thinness 5-9 years              34  NaN
Income composition of resources 167 NaN
Schooling                       163 NaN
Apoorva
  • 147
  • 4
  • 1
    IIUC use `pd.concat([entries_df, pd.DataFrame({'Percentage of missing values': lst}, index=entries_df.index)], axis=1)` – jezrael Jan 23 '23 at 08:47

0 Answers0