【问题标题】:adding for loop or any thing to call list in the function在函数中添加 for 循环或任何要调用列表的东西
【发布时间】:2021-10-23 14:33:54
【问题描述】:

我正在尝试使用 for 循环或其他任何方法将列表放入参数 reporter ='arg'

例如列表['arg','AFG','ALB','DZA'] 然后将它们保存在一个数据框中

import pandas as pd
import world_trade_data as wits    
pd.set_option('display.max_rows', 6)


Countery_IMPORT = wits.get_indicator('MPRT-TRD-VL', reporter='arg', year='all',partner='wld',datasource='tradestats-trade',name_or_id='name')

【问题讨论】:

  • 我用这个 countery = ['AFG','ALB','DZA'] for x in countery: 但没用

标签: python pandas dataframe numpy for-loop


【解决方案1】:

concat的简单列表理解

import pandas as pd
import world_trade_data as wits

pd.set_option("display.max_rows", 6)

Countery_IMPORT = pd.concat(
    [
        wits.get_indicator(
            "MPRT-TRD-VL",
            reporter=arg,
            year="all",
            partner="wld",
            datasource="tradestats-trade",
            name_or_id="name",
        )
        for arg in ["arg", "AFG", "ALB", "DZA"]
    ]
)

Countery_IMPORT

【讨论】:

    猜你喜欢
    • 2015-11-13
    • 2022-11-11
    • 2018-08-07
    • 1970-01-01
    • 1970-01-01
    • 2022-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多