【发布时间】:2022-01-15 21:04:42
【问题描述】:
我正在使用 eurostat 包在 Python 中下载 Eurostat 数据集,而 Dataframe 格式很难使用。我一直在尝试将面板数据转换为时间序列,但没有成功。
我已经对数据进行了一些过滤和清理,但我未能将表格转换为时间序列(我对 Python 还很陌生)。在我的代码下面:
#pip install eurostat
import pandas as pd
import eurostat
# Commercial flights by reporting country – monthly data (source: Eurocontrol)
df_eurostat = eurostat.get_data_df('avia_tf_cm')
df_eurostat = df_eurostat.rename(columns={'geo\\time':'Region'})
# To exclude: 'EU27_2020', 'EU28'
# df_eurostat = df_eurostat.drop(columns='unit').T
country_list = ['AL', 'AT', 'BE', 'BG', 'CH', 'CY', 'CZ', 'DE', 'DK', 'EE', 'EL',
'ES', 'FI', 'FR', 'HR', 'HU', 'IE', 'IS', 'IT', 'LT', 'LU', 'LV',
'ME', 'MK', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RS', 'SE', 'SI',
'SK', 'TR', 'UK']
df_eurostat = df_eurostat[df_eurostat['Region'].isin(country_list)]
df_eurostat = df_eurostat.loc[(df_eurostat['unit']=='NR')]
如果有人能提供帮助,将不胜感激。提前谢谢!
【问题讨论】:
标签: python pandas dataframe time-series