创建一个空的纵向国家数据集
Creating an empty longitudinal country dataset
我想创建一个空的纵向国家周数据集,其中每个国家代表 52 次(一年中的几周),所有其他变量首先填充0秒。它应该看起来像这样:
countries = ['Albania', 'Belgium', ... 'Zimbabwe']
df_weekly = {['country': 'Albania', 'week': 1],
['country': 'Albania', 'week': 2],
...
['country': 'Albania', 'week': 52],
...
['country': 'Zimbabwe', 'week': 52]}
因此我的问题是:我如何从国家列表中得到这样一个纵向国家周数据集。
原来很简单:
country_list = ['Albania', 'Belgium', 'China', 'Denmark']
country = country_list * 52 # multiply by the number of weeks in the year
country.sort()
week = [1, 2, 3, 4, 5] * 4 # multiply by the number of countries
weekly = pd.DataFrame(
{'country': country,
'week': week
})
我想创建一个空的纵向国家周数据集,其中每个国家代表 52 次(一年中的几周),所有其他变量首先填充0秒。它应该看起来像这样:
countries = ['Albania', 'Belgium', ... 'Zimbabwe']
df_weekly = {['country': 'Albania', 'week': 1],
['country': 'Albania', 'week': 2],
...
['country': 'Albania', 'week': 52],
...
['country': 'Zimbabwe', 'week': 52]}
因此我的问题是:我如何从国家列表中得到这样一个纵向国家周数据集。
原来很简单:
country_list = ['Albania', 'Belgium', 'China', 'Denmark']
country = country_list * 52 # multiply by the number of weeks in the year
country.sort()
week = [1, 2, 3, 4, 5] * 4 # multiply by the number of countries
weekly = pd.DataFrame(
{'country': country,
'week': week
})