主頁 >  其他 > python-為什么在python中將多個幀與pandas合并時行會加倍

python-為什么在python中將多個幀與pandas合并時行會加倍

2022-05-30 15:38:49 其他

我正在嘗試合并我用 excel 中的 pandas 讀取的多個年終結果(2013 年到 2021 年) - 以這三年為例,使用以下代碼生成:

HNRrawfile_2018 = HNR_source_path 'HNR_AR2018_XLS_en.xlsx'

df2018_assets = pd.read_excel(
    HNRrawfile_2018,
    sheet_name=assets,
    skiprows=4,
    skipfooter=1,
    usecols=[0, 2])
df2018_assets.columns = ['ITEM', '2018']
df2018_assets['2018'] = df2018_assets['2018'].astype(int)
df2018_assets['ITEM'] = df2018_assets['ITEM'].str.strip().str.lower()
print(df2018_assets)
                                                 ITEM      2019
0          fixed-income securities - held to maturity    223049
1     fixed-income securities - loans and receivables   2194064
2        fixed-income securities - available for sale  38068459
3   fixed-income securities - at fair value throug...    578779
4              equity securities - available for sale     29215
5   other financial assets - at fair value through...    235019
6                                 investment property   1749517
7                                   real estate funds    534739
8                 investments in associated companies    245478
9                               other invested assets   2211905
10                             short-term investments    468350
11                          cash and cash equivalents   1090852
12    total investments and cash under own management  47629426
13                                     funds withheld  10948469
14                                  contract deposits    325302
15                                  total investments  58903197
16          reinsurance recoverables on unpaid claims   2050114
17        reinsurance recoverables on benefit reserve    852598
18                        prepaid reinsurance premium    116176
19  reinsurance recoverables on other technical re...      9355
20                         deferred acquisition costs   2931722
21                                accounts receivable   5269792
22                                           goodwill     88303
23                                deferred tax assets    442469
24                                       other assets    640956
25                          accrued interest and rent     15414
26                               assets held for sale     36308
27                                       total assets  71356404

                                                 ITEM      2018
0          fixed-income securities – held to maturity    249943
1     fixed-income securities – loans and receivables   2398950
2        fixed-income securities – available for sale  33239685
3   fixed-income securities – at fair value throug...    559750
4              equity securities – available for sale     28729
5   other financial assets – at fair value through...    190759
6                                 investment property   1684932
7                                   real estate funds    433899
8                 investments in associated companies    110545
9                               other invested assets   1805281
10                             short-term investments    421950
11                          cash and cash equivalents   1072915
12    total investments and cash under own management  42197338
13                                     funds withheld  10691768
14                                  contract deposits    172873
15                                  total investments  53061979
16          reinsurance recoverables on unpaid claims   2084630
17        reinsurance recoverables on benefit reserve    909056
18                        prepaid reinsurance premium     93678
19  reinsurance recoverables on other technical re...      7170
20                         deferred acquisition costs   2155820
21                                accounts receivable   3975778
22                                           goodwill     85588
23                                deferred tax assets    454608
24                                       other assets    629420
25                          accrued interest and rent     11726
26                               assets held for sale   1039184
27                                       total assets  64508637

                                                 ITEM      2017
0          fixed-income securities – held to maturity    336182
1     fixed-income securities – loans and receivables   2455164
2        fixed-income securities – available for sale  31281908
3   fixed-income securities – at fair value throug...    212042
4              equity securities – available for sale     37520
5   other financial assets – at fair value through...     88832
6                   real estate and real estate funds   1968702
7                 investments in associated companies    121075
8                               other invested assets   1761678
9                              short-term investments    958669
10                          cash and cash equivalents    835706
11    total investments and cash under own management  40057478
12                                     funds withheld  10735012
13                                  contract deposits    167854
14                                  total investments  50960344
15          reinsurance recoverables on unpaid claims   1651335
16        reinsurance recoverables on benefit reserve    959533
17                        prepaid reinsurance premium     96402
18  reinsurance recoverables on other technical re...      7301
19                         deferred acquisition costs   2228246
20                                accounts receivable   3821124
21                                           goodwill     91692
22                                deferred tax assets    466564
23                                       other assets    904253
24                          accrued interest and rent     10052
25                               assets held for sale         0
26                                       total assets  61196846

但是,有些行會翻倍,尤其是固定收益行,它們在 2021 年至 2019 年期間出現在頂部,但從 2018 年開始在底部增加一倍:

                                                 ITEM        2021        2020        2019        2018        2017        2016        2015        2014        2013
0          fixed-income securities - held to maturity     48632.0    185577.0    223049.0         NaN         NaN         NaN         NaN         NaN         NaN
1     fixed-income securities - loans and receivables   2443629.0   2532146.0   2194064.0         NaN         NaN         NaN         NaN         NaN         NaN
2        fixed-income securities - available for sale  45473677.0  38851723.0  38068459.0         NaN         NaN         NaN         NaN         NaN         NaN
3   fixed-income securities - at fair value throug...     81308.0    105711.0    578779.0         NaN         NaN         NaN         NaN         NaN         NaN
4              equity securities - available for sale    314453.0    378422.0     29215.0         NaN         NaN         NaN         NaN         NaN         NaN
5   other financial assets - at fair value through...    248233.0    234689.0    235019.0         NaN         NaN         NaN         NaN         NaN         NaN
6                                 investment property   1818754.0   1589238.0   1749517.0   1684932.0         NaN         NaN         NaN         NaN         NaN
7                                   real estate funds    805912.0    582296.0    534739.0    433899.0         NaN         NaN         NaN         NaN         NaN
8                 investments in associated companies    238110.0    361617.0    245478.0    110545.0    121075.0    114633.0    128008.0    154822.0    144489.0
9                               other invested assets   2941633.0   2794016.0   2211905.0   1805281.0   1761678.0   1764678.0   1544533.0   1316604.0   1023214.0
10                             short-term investments    443793.0    327426.0    468350.0    421950.0    958669.0    838987.0   1113130.0    575300.0    549138.0
11                          cash and cash equivalents   1355114.0   1278071.0   1090852.0   1072915.0    835706.0    848667.0    792604.0    772882.0    642936.0
12    total investments and cash under own management  56213248.0  49220932.0  47629426.0  42197338.0  40057478.0  41793495.0  39346903.0  36228010.0  31875242.0
13                                     funds withheld  10803071.0   9659807.0  10948469.0  10691768.0  10735012.0  11673259.0  13801845.0  15826480.0  14267831.0
14                                  contract deposits    503412.0    298344.0    325302.0    172873.0    167854.0    170505.0    188604.0     92069.0     75541.0
15                                  total investments  67519731.0  59179083.0  58903197.0  53061979.0  50960344.0  53637259.0  53337352.0  52146559.0  46218614.0
16          reinsurance recoverables on unpaid claims   2674107.0   1883270.0   2050114.0   2084630.0   1651335.0   1506292.0   1395281.0   1376432.0   1403804.0
17        reinsurance recoverables on benefit reserve    192039.0    192135.0    852598.0    909056.0    959533.0   1189420.0   1367173.0    676219.0    344154.0
18                        prepaid reinsurance premium    204597.0    165916.0    116176.0     93678.0     96402.0    134927.0    164023.0    149257.0    139039.0
19  reinsurance recoverables on other technical re...      2703.0      1106.0      9355.0      7170.0      7301.0     12231.0      8687.0      5446.0      6893.0
20                         deferred acquisition costs   3350633.0   2857071.0   2931722.0   2155820.0   2228246.0   2198089.0   2094671.0   1914598.0   1672398.0
21                                accounts receivable   7207750.0   5605803.0   5269792.0   3975778.0   3821124.0   3678030.0   3665937.0   3113978.0   2945685.0
22                                           goodwill     83933.0     80965.0     88303.0     85588.0     91692.0     64609.0     60244.0     58220.0     57070.0
23                                deferred tax assets    676344.0    597986.0    442469.0    454608.0    466564.0    408292.0    433500.0    393923.0    508841.0
24                                       other assets    972167.0    858170.0    640956.0    629420.0    904253.0    674389.0    680543.0    618280.0    603627.0
25                          accrued interest and rent     18248.0     18264.0     15414.0     11726.0     10052.0      9978.0      7527.0      4672.0      4193.0
26                                       total assets  82902252.0  71439769.0  71356404.0  64508637.0  61196846.0  63528602.0  63214938.0  60457584.0  53915544.0
27                               assets held for sale         NaN         0.0     36308.0   1039184.0         0.0     15086.0         NaN         0.0     11226.0
28         fixed-income securities – held to maturity         NaN         NaN         NaN    249943.0    336182.0    484955.0   1007665.0   2139742.0   2666787.0
29    fixed-income securities – loans and receivables         NaN         NaN         NaN   2398950.0   2455164.0   2563594.0   2869865.0   2988187.0   3209100.0
30       fixed-income securities – available for sale         NaN         NaN         NaN  33239685.0  31281908.0  32182173.0  29616448.0  26817523.0  22409892.0
31  fixed-income securities – at fair value throug...         NaN         NaN         NaN    559750.0    212042.0    239917.0    108982.0     64494.0     36061.0
32             equity securities – available for sale         NaN         NaN         NaN     28729.0     37520.0    905307.0    452108.0     32804.0     28980.0
33  other financial assets – at fair value through...         NaN         NaN         NaN    190759.0     88832.0     57665.0     39602.0     66394.0     70082.0
34                  real estate and real estate funds         NaN         NaN         NaN         NaN   1968702.0   1792919.0   1673958.0   1299258.0   1094563.0

合并是通過使用外部進行的,因為有些職位每年都不會出現,我想確保從左表和右表中收集每一行:

df_assets_1 = df2021_assets.merge(
    df2020_assets, how='outer', on='ITEM').merge(
    df2019_assets, how='outer', on='ITEM').merge(
    df2018_assets, how='outer', on='ITEM').merge(
    df2017_assets, how='outer', on='ITEM').merge(
    df2016_assets, how='outer', on='ITEM').merge(
    df2015_assets, how='outer', on='ITEM').merge(
    df2014_assets, how='outer', on='ITEM').merge(
    df2013_assets, how='outer', on='ITEM')

我試圖通過

  • 確保專案描述被剝離并且全部小寫
  • 在axis = 1上使用.concat而不是.merge
  • 使用左連接,但這會從右表中洗掉位置(如預期的那樣)
  • 在沒有 on='ITEM' 的情況下嘗試它,但這沒有任何區別

非常感謝您提供任何幫助 - 非常感謝您寶貴的時間!

uj5u.com熱心網友回復:

我在 PowerQuery 中使用 M 檢查了加入的程序,幾乎每個步驟之后都需要清理資料,因為由于財務結果的性質(可能有一個總體的“標題行”(股東)例如價值)和另一行具有相同名稱的持有股東價值的總和)。

因此,在每次外部合并之后,必須在進行下一次外部合并之前洗掉可能的重復項。這導致了重復。

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/482551.html

標籤:Python 熊猫 数据框 加入 合并

上一篇:MySQL-如何為一種產品存盤多種顏色組合?

下一篇:沒有唯一識別符號的內連接

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more