当我尝试合并具有相同行大小的数据时,问题是增加了行
The problem is increased the row when I try to merge data that have the same row size
我们想使用merge方法将修改后的两个数据框合并为一个数据。
每个数据框的形状为 16598 行 × 6 列。
预期结果为(16598 行 × 6 列)。
然而,合并后的结果是(16602 行×7 列),行数增加了四。
我使用的代码如下
total_data = pd.merge(data_01,data_02,on=['Name', 'Platform', 'Year', 'Genre', 'Publisher'])
更具体一点..
'data_01'的列名是'Name'、'Platform'、'Year'、'Genre'、'Publisher'、'NA_Sales'. (16598 行 × 6 列)
'data_02'的列名是'Name'、'Platform'、'Year'、'Genre'、'Publisher'和'EU_Sales'. (16598 行 × 6 列)
两个数据框只是索引号和数据行顺序不同,'Name'、'Platform'、'Year'、'Genre'、'Publisher'是一样的。
只有“NA_Sales”、“EU_Sales”和“年”的值为数字,其余为对象类型。
我想做的...
我想制作一个 DataFrame(16598 行 × 7 列)来组合 Data01 和 Data02。但是,该列不断增加。
data_01(16598行×6列)
Name Platform Year Genre Publisher NA_Sales
1 Candace.. DS 2008.0 Action Destineer 40.0
2 The Mun.. Wii 2009.0 Action Namco.. 170.0
3 Otome .. PS 2010.0 Adventure Alchemist 0.0
4 Deal.. DS 2010.0 Misc Zoo Games 40.0
5 Ben 10.. PS3 2010.0 Platform D3Publisher 120.0
... ... ... ... ... ... ...
16331 Midway.. PS2 2003.0 Misc Midway Games 720000.0
16409 NASCAR.. PS2 2005.0 Racing Electronic.. 530000.0
16483 Super.. SAT 1998.0 Strategy Banpresto 0.0
16493 Morta.. PSV 2012.0 Fighting Warner Bros. 470000.0
16579 Gex:.. PS 1998.0 Platform BMG... 320000.0
data_02(16598行×6列)
Name Platform Year Genre Publisher EU_Sales
1 Candace.. DS 2008.0 Action Destineer 0.0
2 The.. Wii 2009.0 Action Namco ... 0.0
3 Otome.. PSP 2010.0 Adventure Alchemi.. 0.0
4 Deal or.. DS 2010.0 Misc Zoo Games 0.0
5 Ben 10.. PS3 2010.0 Platform D3Publisher 90.0
... ... ... ... ... ... ...
16348 Aladdin.. Wii 2011.0 Racing Big.. 0.0
16375 Kill... XB 2003.0 Shooter Namco.. 50000.0
16385 Tomb.. PS2 2009.0 Action Eidos.. 40000.0
16526 Planet.. GBA 2001.0 Action Titus 0.0
16572 Koihime.. PS4 2016.0 Fighting Yeti 0.0
我想我明白从 Name
到 Publisher
的数据在两个表的索引方面是相同的。
所以只需合并一个数据框中的所有内容和另一列中的一列。
total_data = pd.merge(data_01, data_02.EU_Sales, left_index=True, right_index=True)
我们想使用merge方法将修改后的两个数据框合并为一个数据。 每个数据框的形状为 16598 行 × 6 列。 预期结果为(16598 行 × 6 列)。 然而,合并后的结果是(16602 行×7 列),行数增加了四。 我使用的代码如下
total_data = pd.merge(data_01,data_02,on=['Name', 'Platform', 'Year', 'Genre', 'Publisher'])
更具体一点..
'data_01'的列名是'Name'、'Platform'、'Year'、'Genre'、'Publisher'、'NA_Sales'. (16598 行 × 6 列)
'data_02'的列名是'Name'、'Platform'、'Year'、'Genre'、'Publisher'和'EU_Sales'. (16598 行 × 6 列)
两个数据框只是索引号和数据行顺序不同,'Name'、'Platform'、'Year'、'Genre'、'Publisher'是一样的。
只有“NA_Sales”、“EU_Sales”和“年”的值为数字,其余为对象类型。
我想做的... 我想制作一个 DataFrame(16598 行 × 7 列)来组合 Data01 和 Data02。但是,该列不断增加。
data_01(16598行×6列)
Name Platform Year Genre Publisher NA_Sales
1 Candace.. DS 2008.0 Action Destineer 40.0
2 The Mun.. Wii 2009.0 Action Namco.. 170.0
3 Otome .. PS 2010.0 Adventure Alchemist 0.0
4 Deal.. DS 2010.0 Misc Zoo Games 40.0
5 Ben 10.. PS3 2010.0 Platform D3Publisher 120.0
... ... ... ... ... ... ...
16331 Midway.. PS2 2003.0 Misc Midway Games 720000.0
16409 NASCAR.. PS2 2005.0 Racing Electronic.. 530000.0
16483 Super.. SAT 1998.0 Strategy Banpresto 0.0
16493 Morta.. PSV 2012.0 Fighting Warner Bros. 470000.0
16579 Gex:.. PS 1998.0 Platform BMG... 320000.0
data_02(16598行×6列)
Name Platform Year Genre Publisher EU_Sales
1 Candace.. DS 2008.0 Action Destineer 0.0
2 The.. Wii 2009.0 Action Namco ... 0.0
3 Otome.. PSP 2010.0 Adventure Alchemi.. 0.0
4 Deal or.. DS 2010.0 Misc Zoo Games 0.0
5 Ben 10.. PS3 2010.0 Platform D3Publisher 90.0
... ... ... ... ... ... ...
16348 Aladdin.. Wii 2011.0 Racing Big.. 0.0
16375 Kill... XB 2003.0 Shooter Namco.. 50000.0
16385 Tomb.. PS2 2009.0 Action Eidos.. 40000.0
16526 Planet.. GBA 2001.0 Action Titus 0.0
16572 Koihime.. PS4 2016.0 Fighting Yeti 0.0
我想我明白从 Name
到 Publisher
的数据在两个表的索引方面是相同的。
所以只需合并一个数据框中的所有内容和另一列中的一列。
total_data = pd.merge(data_01, data_02.EU_Sales, left_index=True, right_index=True)