RT,PyCharm
版本号是Community Edition 2017.2.4
https://wx2.sinaimg.cn/mw690/62f40e5bgy1fmnnbkf91ij20qn0goqmj.jpg
以下是脚本
# coding: utf-8
import numpy as np
import pandas as pd
from tempfile import NamedTemporaryFile
np.random.seed(42)
a = np.random.randn(365, 4)
# tmpf = NamedTemporaryFile()
tmpf = './data/t.csv'
store = pd.io.pytables.HDFStore(tmpf)
print store
df = pd.DataFrame(a)
store['df'] = df
print store
print "Get", store.get('df').shape
print "Lookup", store['df'].shape
print "Dotted", store.df.shape
del store['df']
print "After del\n", store
print "Before close", store.is_open
store.close()
print "After close", store.is_open
df.to_hdf(tmpf, 'data', format='table')
print pd.read_hdf(tmpf, 'data', where=['index>363'])
以下是运行的结果,之前还只是以为重复打印。刚开始t.csv
文件是不存在的,所以 HDFStore 的结果是Empty
。但是查看运行结果发现第二次的文件结果不为空,由此可以程序又运行了一次。
# 第一次运行
C:\APPS\Anaconda\python.exe D:/DATA/DEV/python/py.py
<class 'pandas.io.pytables.HDFStore'>
File path: ./data/t.csv
Empty #结果为空
<class 'pandas.io.pytables.HDFStore'>
File path: ./data/t.csv
/df frame (shape->[365,4])
Get (365, 4)
Lookup (365, 4)
Dotted (365, 4)
After del
<class 'pandas.io.pytables.HDFStore'>
File path: ./data/t.csv
Empty
Before close True
After close False
0 1 2 3
364 0.753342 0.381158 1.289753 0.673181
# 第二次运行
<class 'pandas.io.pytables.HDFStore'>
File path: ./data/t.csv
# 文件结果不为空,由此可以程序又运行了一次
/data frame_table (typ->appendable,nrows->365,ncols->4,indexers->[index])
<class 'pandas.io.pytables.HDFStore'>
File path: ./data/t.csv
/data frame_table (typ->appendable,nrows->365,ncols->4,indexers->[index])
/df frame (shape->[365,4])
Get (365, 4)
Lookup (365, 4)
Dotted (365, 4)
After del
<class 'pandas.io.pytables.HDFStore'>
File path: ./data/t.csv
/data frame_table (typ->appendable,nrows->365,ncols->4,indexers->[index])
Before close True
After close False
0 1 2 3
364 0.753342 0.381158 1.289753 0.673181
Process finished with exit code 0
请问是什么原因?
1
scriptB0y 2017-12-21 11:16:11 +08:00
提问的时候提供一个最小的重现例子
|