2016-09-22 7 views
2

weather.h5という名前のh5ストアがあります。私のデフォルトのPython環境は3.5.2です。この店を読むと、私はTypeError: Already tz-aware, use tz_convert to convertになります。pandasを使用してh5ファイルを読み込んだときにpython 3(2ではなく)

私はpd.read_hdf('weather.h5','weather_history')pd.io.pytables.HDFStore('weather.h5')['weather_history]の両方を試しましたが、何か問題が発生しました。

私はPython 2.7環境でh5を開くことができます。これはPython 3/pandasのバグですか?

+0

'weather_store = pd.io.pytables.HDFStore( 'weather.h5')を使用してh5を読み込むことができます'、しかし、' weather_store ['weather_history'] 'を使ってテーブルを取得しようとすると、' TypeError'が呼び出されます。 –

答えて

0

私は同じ問題があります。私はAnaconda Pythonを使っています:3.4.5と2.7.3。どちらもパンダ0.18.1を使用しています。

generate.py(Python2で実行される):

import pandas as pd 
from pandas import HDFStore 

index = pd.DatetimeIndex(['2017-06-20 06:00:06.984630-05:00', '2017-06-20 06:03:01.042616-05:00'], dtype='datetime64[ns, CST6CDT]', freq=None) 
p1 = [0, 1] 
p2 = [0, 2] 

# Saving any of these dataframes cause issues 
df1 = pd.DataFrame({"p1":p1, "p2":p2}, index=index) 
df2 = pd.DataFrame({"p1":p1, "p2":p2, "i":index}) 

store = HDFStore("./test_issue.h5") 
store['df'] = df1 
#store['df'] = df2 
store.close() 

read_issue.py:Python2で

import pandas as pd 
from pandas import HDFStore 

store = HDFStore("./test_issue.h5", mode="r") 
df = store['/df'] 
store.close() 

print(df) 

実行read_issue.pyはここから

は再現例であります問題は発生せず、次の出力を生成します。

p1 p2 

2017-06-20 11:00:06.984630-05:00 0 0 2017-06-20 11:03:01.042616-05:00 1 2

しかしのpython3でそれを実行しているが、このトレースバックでエラーが発生しますので、

Traceback (most recent call last): File "read_issue.py", line 5, in df = store['df'] File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 417, in getitem return self.get(key) File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 634, in get return self._read_group(group) File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 1272, in _read_group return s.read(**kwargs) File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 2779, in read ax = self.read_index('axis%d' % i) File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 2367, in read_index _, index = self.read_index_node(getattr(self.group, key)) File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 2492, in read_index_node _unconvert_index(data, kind, encoding=self.encoding), **kwargs) File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/indexes/base.py", line 153, in new result = DatetimeIndex(data, copy=copy, name=name, **kwargs) File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/util/decorators.py", line 91, in wrapper return func(*args, **kwargs) File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/tseries/index.py", line 321, in new raise TypeError("Already tz-aware, use tz_convert " TypeError: Already tz-aware, use tz_convert to convert. Closing remaining open files:./test_issue.h5...done

、インデックスとの問題があります。あなたはgenerate.py(列としてではなく、インデックスとして日時)でDF2保存する場合は、その後、read_issue.py中のpython3は異なるエラーが発生します。

Traceback (most recent call last): File "read_issue.py", line 5, in df = store['/df'] File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 417, in getitem return self.get(key) File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 634, in get return self._read_group(group) File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 1272, in _read_group return s.read(**kwargs) File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/io/pytables.py", line 2788, in read placement=items.get_indexer(blk_items)) File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/core/internals.py", line 2518, in make_block return klass(values, ndim=ndim, fastpath=fastpath, placement=placement) File "/home/denper/anaconda3/envs/py34/lib/python3.4/site-packages/pandas/core/internals.py", line 90, in init len(self.mgr_locs))) ValueError: Wrong number of items passed 2, placement implies 1 Closing remaining open files:./test_issue.h5...done

また、あなたがのpython3でgenerate_issue.pyを実行した場合(df1またはdf2のいずれかを保存する)、Python3またはPython2でread_issue.pyを実行するのに問題はありません

関連する問題