接种月龄计算
brk <- read_csv("/mnt/c/Users/xuefeng/Desktop/brk.csv",locale = locale(encoding = 'GB18030')) %>% clean_names() %>% mutate(jz_sj=ymd_hms(jz_sj),csrq=ymd(csrq),jzyl = interval(csrq, jz_sj) %/% months(1),shi=str_sub(gldw_bm,1,4)) brk %>% filter(csrq <= ymd('2023-12-30') & jz_zc == 1) %>% group_by(shi) %>% summarise(count = n(), jzyl_3 = sum(jzyl == 3,na.rm = T),jzyl_3/count*100) %>% writexl::write_xlsx("/mnt/c/Users/xuefeng/Desktop/brk2024_3.xlsx") import pandas as pd import numpy as np import janitor from pandas . tseries . offsets import MonthEnd from datetime import datetime brk = pd . read_csv ( "/mnt/c/Users/xuefeng/Desktop/brk.csv" , encoding = 'GB18030' ) brk = ( brk . rename ( columns = lambda x : x .lower().replace( ' ' , '_' )) . assign ( jz_sj = lambda df : pd . to_datetime ( df [ 'jz_sj' ], format = '%Y-%m-