【发布时间】:2020-12-08 10:28:13
【问题描述】:
我在示例中有一个 .txt 文件,如下所示
Name: XYZ
Date of Service: 12/27/2018
Speaker ID: 10101
Visit Start: 06/07/2018
Visit End: 06/18/2018
Recipient:
CHIEF COMPLAINT:
Liver discomfort.
我想解析.txt文件并写入excel
Name Date of Service Speaker ID ....
XYZ 12/27/2018 10101
我写了以下代码
import xlwt
import xlrd
textfiles = Input.txt
for a in textfiles:
f = open(textfile, 'r+')
row_list = []
for row in f:
row_list.append(row.split(':'))
column_list = zip(*row_list)
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('Sheet1')
i = 0
for column in column_list:
for item in range(len(column)):
worksheet.write(item, i, column[item])
i+=1
workbook.save(textfile + '.xls')
但我得到的结果是用 excel 写在一个列中
Name
XYZ
Speaker ID
10101
...
CHIEF COMPLAINT
Liver discomfort
即使在 Pandas 中,我也尝试过它给了我相同的输出。有人可以帮助我如何在行中编写标题并将其对应的数据写在 col 中。
谢谢 米拉。
完整的输入文件
Patient Name: XYZ
Date of Service: 12/27/2018
Speaker ID: 10101
Visit Start: 06/07/2018
Visit End: 06/18/2018
Recipient:
CHIEF COMPLAINT:
Chest discomfort.
HISTORY OF PRESENT ILLNESS:
The patient is a 64-year-old Caucasian female with a past medical history which is remarkable for severe COPD as well as severe coronary artery disease. She has a complex cardiac history including a coronary anomaly and coronary fistula with coronary bypass surgery with a left internal mammary artery graft to left anterior descending coronary artery in 2003. Subsequently in 2007, for symptoms of a substernal chest heaviness, she was evaluated and wound up having a right coronary stent placed. Her most recent angiography in 2012 demonstrated a patent left internal mammary artery to the LAD and patent other stents including the right coronary stent noted above. She had sternal wires removed in 2012 because of sharp substernal chest discomfort. She is a former smoker who quit many years ago prior to her coronary bypass graft surgery, but unfortunately has gone on to still have significant COPD. Over the past several days to few weeks, she has had increasing amounts of shortness of breath, increasing amounts of substernal heaviness, mild to moderate in nature, coming on with exertion and going away with rest, not dissimilar from presentations in the past with coronary disease. It should also note that she brought up the fact that she has "passed many stress tests with flying colors" and then went on to have coronary blockages. She has been hospitalized now with an apparent exacerbation of COPD and this has not been completely cleared. She denies any recent fevers or chills. There has been no nausea, no vomiting, no abdominal pain, no focal neurologic complaints, no abnormal bleeding.
REVIEW OF SYSTEMS:
Complete review of systems in detail is as noted above, pertinent positives and negatives are as noted above, all other systems were reviewed and were negative.
PAST MEDICAL HISTORY:
Also remarkable for lifelong asthma with COPD, hypothyroidism, hypertension, and gastroesophageal reflux disease.
ALLERGIES:
Include,
1. SULFA.
2. PENICILLIN.
3. CEPHALOSPORINS.
SOCIAL HISTORY:
As noted above.
FAMILY HISTORY:
Positive for "lots of heart disease."
PHYSICAL EXAMINATION:
VITAL SIGNS: Remarkable most recently for a blood pressure of 128/60, a respiratory rate of 16, a pulse of 81, and a temperature of 36.7 degrees Centigrade. Her saturation currently is 96% on room air.
HEENT: Negative.
NECK: Her jugular venous pressure is not elevated. Her carotids are 2+ bilateral. No bruits are heard.
LUNGS: Have diffuse wheezing throughout both end-expiratory as well as inspiratory. A few scattered rhonchi are noted bilaterally. Mild kyphosis of her spine is noted.
CARDIOVASCULAR: Cardiac auscultation demonstrates regular rate and rhythm, normal S1, normal S2. No murmurs, gallops, or rubs are appreciated.
GASTROINTESTINAL: Soft, nontender, with normal active bowel sounds.
EXTREMITIES: Demonstrate no cyanosis, clubbing or edema.
NEUROLOGIC: She is nonfocal and is able to move all extremities.
PSYCHIATRIC: She is awake, alert and oriented x3 and cooperative.
SKIN: Warm and dry.
DIAGNOSTIC DATA:
Her electrocardiogram shows sinus rhythm, incomplete right bundle-branch block, nonspecific anterior T-wave changes, and this is largely unchanged compared to previous tracings.
Her last echocardiogram, which was in 2006, demonstrated normal LV systolic function and her right atrium and right ventricle appeared at that time to be normal.
Her cardiac catheterization in 01/2012 showed the aforementioned patent LIMA bypass to the LAD. There was a patent LAD stent. There was a patent stent to the right posterior descending coronary artery. There was an anomalous left coronary artery arising from the right coronary cusp, normal LV systolic function and mild mitral regurgitation.
Her chest x-ray directly reviewed by me, as was her previous EKG, showed clearcut changes associated with COPD, hyperinflation, no infiltrates.
IMPRESSION:
The patient had symptoms of chest tightness and heaviness when she presented with her catheterization for 2012 and at that time, all of her major coronary arteries were patent. Her course here has been predominantly pulmonary. Her laboratories include a BNP which is only 40. Her one cardiac troponin was 0.02. Her symptoms are unlikely to be coronary. She had a nuclear stress test, which by her report a year ago this summer, appeared to be "normal." We will check her echocardiogram for any interval change in LV systolic function, in particular for regional wall motion abnormalities. If there are no regional wall motion abnormalities, I think she will be able to be discharged from a cardiac perspective, although her lungs are clearly still with significant finding of wheezing. With regard to her coronary status, she is on atorvastatin 20 per day and this should be continued. Blood pressure on steroid taper will need to be watched closely.
PLAN:
No Symptoms
根据文件,计划将是最后一个标题。
【问题讨论】:
标签: python excel pandas parsing header