You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何按年度与受援国汇总promised aid和provided aid的总金额?

Hey there! Let's walk through how to calculate those yearly aid totals per country—this is a standard aggregation task, and there are straightforward solutions depending on the tool you're using. I'll cover the most common options below:

Using Excel

If you're working with a spreadsheet, a Pivot Table is the easiest way to get this done:

  • First, select your entire dataset (including the header row)
  • Go to the Insert tab and click PivotTable, then choose where you want the result to appear
  • In the PivotTable Fields pane:
    • Drag year and rcode into the Rows area (this will group your data by year first, then country)
    • Drag promised aid and provided aid into the Values area
    • Double-check the aggregation method: by default, it might use "Count"—click the value field, select Value Field Settings, and switch to Sum
  • You’ll end up with a table that shows exactly what you need: e.g., 2002 → Afghanistan → total promised aid = 20M, total provided aid = 18M.
Using Python (Pandas)

If you're using Python for data analysis, Pandas makes this a breeze (plus a filter if you need to limit to 2002-2012):

import pandas as pd

# Load your data into a DataFrame (adjust the path/loading method as needed)
df = pd.read_csv("your_aid_data.csv")

# Filter to only 2002-2012 if your dataset includes other years
filtered_df = df[(df["year"] >= 2002) & (df["year"] <= 2012)]

# Group by year and country code, then sum the two aid columns
summary_df = filtered_df.groupby(["year", "rcode"])[["promised aid", "provided aid"]].sum().reset_index()

# View the first few rows of the result
print(summary_df.head())
  • The groupby method clusters your data by year and rcode, sum() calculates the total for each aid type, and reset_index() turns the grouped columns back into regular columns for easier viewing and further analysis.
Using R (with dplyr)

For R users, the dplyr package provides a clean, readable workflow for this task:

library(dplyr)

# Load your data (adjust the file path or loading function as needed)
df <- read.csv("your_aid_data.csv")

# Filter to 2002-2012, group by year and country, then compute totals
summary_df <- df %>%
  filter(year >= 2002 & year <= 2012) %>%
  group_by(year, rcode) %>%
  summarise(
    total_promised = sum(`promised aid`, na.rm = TRUE),
    total_provided = sum(`provided aid`, na.rm = TRUE),
    .groups = "drop"
  )

# Preview the result
head(summary_df)
  • filter() narrows down the dataset to your target year range, group_by() sets up the grouping structure, and summarise() calculates the total aid values. The na.rm = TRUE parameter ensures missing values don't break your sum calculations, and .groups = "drop" returns a regular data frame instead of a grouped one.

A quick tip: If your dataset has missing values in the aid columns, all the methods above include ways to ignore blank/NaN cells so they don't skew your totals.

内容的提问来源于stack exchange,提问作者nikip

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:07:19