【发布时间】:2018-04-22 06:32:22
【问题描述】:
我使用的是 pandasdmx 0.7.0 版,虽然我在使用频率维度的 OECD 数据集方面取得了成功,但还有其他数据集,例如 Fossil Fuel Supports 数据集,其中没有频率维度m 无法创建 pandas DataFrame,如下所示:
from pandasdmx import Request
# http://stats.oecd.org/sdmx-json/data/FFS_BRA/all/all
oecd = Request('OECD')
try:
data_response = oecd.data(resource_id='FFS_BRA', key='all/all')
except UnicodeDecodeError:
pass
except KeyError:
pass
else:
oecd_data = data_response.data
print(oecd_data.dim_at_obs)
series_list = list(oecd_data.series)
print(len(series_list))
print(series_list[0].key)
print(set(s.key.FUEL for s in oecd_data.series))
fuel = (s for s in oecd_data.series if s.key.FUEL == 'HARDCOAL')
df = data_response.write(fuel)
print("completed ...")
Output:
TIME_PERIOD
25
SeriesKeyTuple(MEA='BRA_DT_03', FUEL='HARDCOAL', IND='CSE',INC='CONSUMPTION', STG='GENER', MEC='DT', LVL='FED')
{'NONBIOJETK', 'LIGNITE', 'HARDCOAL', 'NAPHTHA', 'NONBIODIES', 'CRUDEOIL', 'RESFUEL', 'NATGAS', 'NGL', 'LPG', 'NONBIOGASO'}
File "stackoverflow_dataframe.py", line 23, in <module>
df = data_response.write(fuel)
File "pandasdmx\api.py", line 635, in write
return self._writer.write(source=source, **kwargs)
File "pandasdmx\writer\data2pandas.py", line 109, in write
reverse_obs, fromfreq, parse_time))
File "pandasdmx\writer\data2pandas.py", line 107, in <genexpr>
series_list = list(s for s in self.iter_pd_series(
File "pandasdmx\writer\data2pandas.py", line 228, in iter_pd_series
obs_values, index=series_index, name=series.key)
UnboundLocalError: local variable 'series_index' referenced before assignment
这是非频率维度数据集的正确方法,还是我只是编码错误?
【问题讨论】: