openai

 import pandas as pd

import numpy as np

import openai

import re

import time


df=(

    pd.read_excel(r"/mnt/d/df2.xlsx",sheet_name=0)

)


# 认证API密钥

openai.api_key = "sk-"


result=[]

for i in df.A[100:]:

    time.sleep(1)

    completion = openai.ChatCompletion.create(model="gpt-3.5-turbo",

                                              messages=[{"role": "user", "content": f"{i}最可能的ICD10的诊断编码"}])

    result.append([i,completion.choices[0].message.content])

    


jb = (

      pd.DataFrame(result,columns=['name', 'zhenduan'])

      .assign(icd=lambda x:x.zhenduan.str.extract(r'([A-Z]\d{2})'))

      )


(

     df.merge(jb,how='left',left_on='A',right_on='name')

     .to_excel('/mnt/d/month2_1.xlsx')

)


icd=(

     pd.read_excel('/mnt/d/3位代码类目表(ICD-10).xls')

 )


month1=(

     pd.read_excel('/mnt/d/month2.xlsx')

     .merge(icd,how='left',left_on='icd',right_on='类目编码')

     .loc[:,['类目名称','icd','s2021','s2022']]

     .groupby(['类目名称','icd'],as_index=False)

     .agg(s1=pd.NamedAgg("s2021",np.sum),

          s2=pd.NamedAgg("s2022",np.sum))

     .to_excel('/mnt/d/m2.xlsx')

)

评论

此博客中的热门博文

V2ray websocket(ws)+tls+nginx分流

Rstudio 使用代理