久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Pandas-通過對(duì)列和索引的值求和來合并兩個(gè)數(shù)據(jù)框

Pandas- merging two dataframe by sum the values of columns and index(Pandas-通過對(duì)列和索引的值求和來合并兩個(gè)數(shù)據(jù)框)
本文介紹了Pandas-通過對(duì)列和索引的值求和來合并兩個(gè)數(shù)據(jù)框的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我想按索引和列合并兩個(gè)數(shù)據(jù)集.

I want to merge two datasets by indexes and columns.

我想合并整個(gè)數(shù)據(jù)集

df1 = pd.DataFrame([[1, 0, 0], [0, 2, 0], [0, 0, 3]],columns=[1, 2, 3])
df1
    1   2   3
0   1   0   0
1   0   2   0
2   0   0   3

df2 = pd.DataFrame([[0, 0, 1], [0, 2, 0], [3, 0, 0]],columns=[1, 2, 3])
df2
    1   2   3
0   0   0   1
1   0   2   0
2   3   0   0

我已經(jīng)嘗試過這段代碼,但我得到了這個(gè)錯(cuò)誤.我不明白為什么它將軸的大小顯示為錯(cuò)誤.

I have tried this code but I got this error. I can't get why it shows the size of axis as an error.

df_sum = pd.concat([df1, df2])
       .groupby(df2.index)[df2.columns]
       .sum().reset_index()

ValueError: Grouper and axis must be same length

這就是我預(yù)期的 df_sum 的輸出

This was what I expected the output of df_sum

df_sum
    1   2   3
0   1   0   1
1   0   4   0
2   3   0   3

推薦答案

你可以使用:df1.add(df2, fill_value=0).它會(huì)將 df2 添加到 df1 中,并且它會(huì)將 NAN 值替換為 0.

You can use :df1.add(df2, fill_value=0). It will add df2 into df1 also it will replace NAN value with 0.

>>> import numpy as np
>>> import pandas as pd
>>> df2 = pd.DataFrame([(10,9),(8,4),(7,np.nan)], columns=['a','b'])
>>> df1 = pd.DataFrame([(1,2),(3,4),(5,6)], columns=['a','b'])
>>> df1.add(df2, fill_value=0)

    a     b
0  11  11.0
1  11   8.0
2  12   6.0

這篇關(guān)于Pandas-通過對(duì)列和索引的值求和來合并兩個(gè)數(shù)據(jù)框的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個(gè)矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測(cè)和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個(gè)矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測(cè)圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測(cè)圖像中矩形的中心和角度)
主站蜘蛛池模板: 国产午夜精品久久 | 黄视频免费观看 | 日韩视频二区 | 在线免费观看一区二区 | 黄色毛片黄色毛片 | 亚洲成人网在线播放 | 国产99久久精品一区二区永久免费 | 特黄小视频| 日韩免费网站 | 亚洲午夜精品久久久久久app | 91在线看 | 免费一级做a爰片久久毛片潮喷 | 午夜天堂精品久久久久 | 精品久久久久久久人人人人传媒 | 亚洲精品成人av久久 | 国产久视频 | 91免费入口| 久久久久久久久淑女av国产精品 | 欧美日本韩国一区二区三区 | 日本黄色大片免费看 | 欧美成人黄色小说 | 国产成人a亚洲精品 | 中文字幕日韩欧美一区二区三区 | 国产日韩欧美一区二区 | 国产精品久久久久久久久图文区 | 成人精品鲁一区一区二区 | 99热在这里只有精品 | www亚洲精品 | 久久精品国产一区 | 在线免费av电影 | 日韩精品无码一区二区三区 | 亚洲国产中文在线 | 久久亚洲经典 | 一区二区国产精品 | 久久免费香蕉视频 | 男人天堂免费在线 | 日日天天 | 欧美综合色 | 羞羞视频在线观看免费观看 | 91精品国产综合久久久久久 | 97久久精品 |