&引用;“已经意识到”;使用pandas、python 3(但不是2)读取h5文件时出错
我有一家名为&引用;“已经意识到”;使用pandas、python 3(但不是2)读取h5文件时出错,python,python-3.x,pandas,timezone,hdf5,Python,Python 3.x,Pandas,Timezone,Hdf5,我有一家名为weather.h5的h5商店。我的默认Python环境是3.5.2。当我试图阅读此存储时,我得到TypeError:ready tz aware,使用tz_convert to convert 我尝试了pd.read\u hdf('weather.h5','weather\u history')和pd.io.pytables.HDFStore('weather.h5')['weather\u history],但不管怎样,我都会得到错误 我可以在Python 2.7环境中打开h5。
weather.h5
的h5商店。我的默认Python环境是3.5.2。当我试图阅读此存储时,我得到TypeError:ready tz aware,使用tz_convert to convert
我尝试了pd.read\u hdf('weather.h5','weather\u history')
和pd.io.pytables.HDFStore('weather.h5')['weather\u history]
,但不管怎样,我都会得到错误
我可以在Python 2.7环境中打开h5。这是Python 3/pandas中的一个bug吗?我也有同样的问题。我使用的是蟒蛇:3.4.5和2.7.3。两者都使用熊猫0.18.1 以下是一个可复制的示例: generate.py(将使用Python2执行): 请阅读_issue.py:
import pandas as pd
from pandas import HDFStore
store = HDFStore("./test_issue.h5", mode="r")
df = store['/df']
store.close()
print(df)
在Python2中运行read_issue.py没有问题,并生成以下输出:
2017-06-20 11:00:06.984630-05:00
2017-06-20 11:03:01.042616-05:00 12
但在Python3中运行它会产生此回溯错误:
回溯(最近一次呼叫最后一次):
文件“read_issue.py”,第5行,在
df=存储['df']
文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/io/pytables.py”,第417行,在getitem
返回self.get(键)
get中的文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/io/pytables.py”,第634行
返回自读组(组)
文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/io/pytables.py”,第1272行,在“读取”组中
返回s.read(**kwargs)
文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/io/pytables.py”,第2779行,已读
ax=self.read\u索引('轴%d'%i)
文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/io/pytables.py”,第2367行,在read_索引中
_,index=self.read\u index\u节点(getattr(self.group,key))
文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/io/pytables.py”,第2492行,位于read_index_节点中
_unsert_索引(数据、种类、编码=self.encoding),**kwargs)
文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/index/base.py”,第153行,在新建
结果=日期时间索引(数据,副本=副本,名称=名称,**kwargs)
包装器中的文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/util/decorators.py”,第91行
返回函数(*args,**kwargs)
文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/tseries/index.py”,第321行,在新建
raise TypeError(“已识别tz,使用tz_转换”
TypeError:已识别tz,请使用tz_convert进行转换。
关闭其余打开的文件:./test_issue.h5…完成
因此,索引存在问题。但是,如果将df2保存在generate.py中(日期时间作为列,而不是索引),则read_issue.py中的Python3会产生不同的错误:
回溯(最近一次呼叫最后一次):
文件“read_issue.py”,第5行,在
df=store['/df']
文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/io/pytables.py”,第417行,在getitem
返回self.get(键)
get中的文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/io/pytables.py”,第634行
返回自读组(组)
文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/io/pytables.py”,第1272行,在“读取”组中
返回s.read(**kwargs)
文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/io/pytables.py”,第2788行,已读
placement=项目。获取索引器(blk\U项目))
文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/core/internals.py”,第2518行,在make_块中
返回klass(值,ndim=ndim,fastpath=fastpath,placement=placement)
文件“/home/denper/anaconda3/envs/py34/lib/python3.4/site packages/pandas/core/internals.py”,第90行,在init
len(自我管理(locs)))
ValueError:传递的项目数错误2,放置意味着1
关闭其余打开的文件:./test_issue.h5…完成
另外,如果您在Python3中执行generate_issue.py(保存df1或df2),那么在Python3或Python2中执行read_issue.py也没有问题。请注意,我可以使用
weather\u store=pd.io.pytables.HDFStore('weather.h5')
加载h5,但这是在我尝试使用weather\u store['weather\u history'获取表时发生的
提示出现TypeError
。
import pandas as pd
from pandas import HDFStore
store = HDFStore("./test_issue.h5", mode="r")
df = store['/df']
store.close()
print(df)
p1 p2