ibis 按周统计
import ibis
import pandas as pd
from ibis import _
import ibis.selectors as s
ibis.options.interactive = True
def load_excel_to_ibis(excel_path):
try:
# 读取Excel文件
df = pd.read_excel(excel_path)
# 将所有object类型的列转换为字符串
for col in df.select_dtypes(include=['object']).columns:
df[col] = df[col].astype(str)
# 转换为Ibis表格
ibis_table = ibis.memtable(df)
return ibis_table
except Exception as e:
print(f"错误: {str(e)}")
return None
dq= load_excel_to_ibis("/mnt/c/users/xuefe/Downloads/百日咳分日发病.xlsx")
tj=(
dq
.mutate(时间=_.时间.cast('date'))
.mutate(zhou=_.时间.week_of_year())
.group_by(_.zhou)
.aggregate(fabingshu=_.发病数.sum())
.execute()
)
tj.to_excel('/mnt/c/users/xuefe/Downloads/zhoutj.xlsx',index=False)
# con=ibis.connect("duckdb://")
con=ibis.duckdb.connect(':memory:')
tmp = pd.read_csv('/mnt/c/users/xuefe/Downloads/报告卡2025-03-11+15_55_57.csv', encoding='gb18030')
brk = ibis.memtable(tmp)
print(ibis.__version__)
tmp2=(
brk
.mutate(年龄1=_.年龄.contains('岁'))
.filter(_.年龄1==False)
.execute()
)
tmp2=(
brk
.filter(_.年龄.contains('岁'))
.execute()
)
tmp2 = (
brk
.filter(_.性别=='女')
.execute()
)
评论
发表评论