Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

python - How to transform table with JSON documents columns to several panda data frames


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try working this into a lambda function. loop through dictionaries to separate your values. Assumes principal diagnosis is always single value, but can have 1 or more secondary.

data_dict = [{"icd10":"I611","icd10Name":"Intracerebral haemorrhage in hemisphere, cortical","diagType":"1","diagTypeName":"Principal Diagnosis"},{"icd10":"I10","icd10Name":"Essential (primary) hypertension","diagType":"2","diagTypeName":"Comorbidity (??????????????????????)"},{"icd10":"E789","icd10Name":"Disorder of lipoprotein metabolism,unspecified","diagType":"2","diagTypeName":"Comorbidity (??????????????????????)"}]


co_diag = []
for d in data_dict:
    if 'Principal Diagnosis' in d.values():
        pd = d['icd10']
    else:
        co_diag.append(d['icd10'])
        co_diag_str = ', '.join(co_diag)

within the steps you should be able to write columns you need.

Output if the loop:

In [19]: co_diag_str
Out[19]: 'I10, E789'

In [20]: pd
Out[20]: 'I611'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...