鱼C论坛

 找回密码
 立即注册
查看: 1322|回复: 0

pandas使用HDF5存储文件,对存储模式为table的数据使用select方法进行数据筛选时报错

[复制链接]
发表于 2022-3-27 23:09:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
在使用pandas以HDF5数据格式进行文件存储时,使用.put方法写入的dataframe数组存储模式为“table”,之后想使用select方法获取部分index下部分columns中满足特定条件的数据,代码实现如下:
import numpy as np
import pandas as pd
date_series=pd.date_range('2000-01-01',periods=8000)
date_arr=pd.Series(date_series.values)
arr_1=np.random.randint(10000,100000,(8000,5))
sales_df1=pd.DataFrame(arr_1,columns=['A','B','C','D','E'])
arr_2=np.random.randint(100000,1000000,(8000,5))
sales_df2=pd.DataFrame(arr_2,columns=['F','G','H','I','J'])
store=pd.HDFStore('mydata.h5')
store['idx'],store['col_1']=date_arr,sales_df1
store.put('col_2',sales_df2,format='table')
print(store['idx'],store['col_1'],store['col_2'],sep='\n')
df_1=store.select('col_2',where=['index>1000 and index<=2000'],columns=['G','H'])  #  可以正常运行
print(df_1) 
df_2=store.select('col_2', where=["index>1000 and index <=5000 and store['col_2']['G'] >= 500000"], columns=['G', 'H'])  
#  运行报错:TypeError: 'Series' objects are mutable, thus they cannot be hashed
print(df_2)
如果想要实现筛选出col_2中index在1000~5000之间,columns为G和H中G列值大于500000的数据应该如何编写代码呢?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-7 02:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表