熊猫pd.merge给nan

时间:2020-04-27 02:10:08

标签: python pandas dataframe left-join

我有两个数据框,我需要根据一个列进行合并/合并。当我尝试加入/合并它们时,新列将显示NaN。

基本上,我需要在数据帧上执行Left Join,将df_user视为左侧的数据帧。

PS:两个数据框上的列具有相同的数据类型。

请在下面找到数据框-

df_user.dtypes

App                       category
Sentiment                     int8
Sentiment_Polarity         float64
Sentiment_Subjectivity     float64

df_play.dtypes
App               category
Category          category
Rating             float64
Reviews            float64
Size               float64
Installs             int64
Type                  int8
Price              float64
Content Rating        int8
Installs_Cat          int8


df_play.head()

    App             Category  Rating    Reviews Size    Installs    Type    Price   Content Installs_Cat
0   SPrapBook   ART_AND_DESIGN  4.1      159       19   10000         0       0        0         9
1   U Launcher  ART_AND_DESIGN  4.5      87510     25   5000000       0       0        0         14
2   Sketch -    ART_AND_DESIGN  4.3      215644    2.8  50000000      0       0        1         16
3   Pixel Dra   ART_AND_DESIGN  4.4      967       5.6  100000        0       0        0         11
4   Paper flo   ART_AND_DESIGN  3.8      167       19   50000         0       0        0         10


df_user.head()


                App           Sentiment     Sentiment_Polarity  Sentiment_Subjectivity
0   10 Best Foods for You         2                1.00              0.533333
1   10 Best Foods for You         2                0.25              0.288462
3   10 Best Foods for You         2                0.40              0.875000
4   10 Best Foods for You         2                1.00              0.300000
5   10 Best Foods for You         2                1.00              0.300000

我尝试了以下两个代码-

result = pd.merge(df_user, df_play, how='left', on='App')
result = df_user.join(df_play.set_index('App'),on='App',how='left',rsuffix='_y')

但是我只有-

App Sentiment   Sentiment_Polarity  Sentiment_Subjectivity  Category    Rating  Reviews Size    Installs    Type    Price   Content Rating  Installs_Cat
0   10 Best Foods for You   2   1.00        0.533333    NaN NaN NaN NaN NaN NaN NaN NaN NaN
1   10 Best Foods for You   2   0.25        0.288462    NaN NaN NaN NaN NaN NaN NaN NaN NaN
2   10 Best Foods for You   2   0.40        0.875000    NaN NaN NaN NaN NaN NaN NaN NaN NaN
3   10 Best Foods for You   2   1.00        0.300000    NaN NaN NaN NaN NaN NaN NaN NaN NaN
4   10 Best Foods for You   2   1.00        0.300000    NaN NaN NaN NaN NaN NaN NaN NaN NaN

请原谅我进行格式化。

0 个答案:

没有答案