|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
打算对出院的数据进行统计,对 周一华 在今年第一次住院的信息调出来,打印出来,再存在excel表中。
请问应该如何处理
import pandas as pd
import openpyxl
pd.set_option('display.max_colwidth',None)
def input_dischagename():
data = pd.read_excel(r'L:\python 读excel\123.xlsx',sheet_name='1')
printe(data.head(2))
raw_data=data[data.姓名 =='周一华']
raw_data=raw_data.sort_values(by='出院日期') # 按照出院日期排序
data=raw_data.ix[1].values # 取第二行,即表头之后的一行。 # 这步显示不对
print(data) 把第二行打印出来
# 怎么把这行存入excel表中?
input_dischagename()
运行后
出院日期 科室 床号 住院号 姓名 性别 年龄 入本区时间 诊断 状态 出院主要诊断 \
0 19-04-02 XXXXXX NaN D860906 XXX 男 90Y 2019/03/18 NaN 出院病人 脑梗死后遗症
1 19-04-02 XXXXXX NaN D751469 XXX 男 96Y 2019/03/18 NaN 出院病人 高血压
סÔooÅ
0 D0000860906
1 D0000751469
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexes\base.py", line 2657, in get_loc
return self._engine.get_loc(key)
File "pandas\_libs\index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 987, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 993, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "L:\python 读excel\read excel4.py", line 13, in <module>
input_dischagename()
File "L:\python 读excel\read excel4.py", line 11, in input_dischagename
data=raw_data.ix[0].values
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 126, in __getitem__
return self._getitem_axis(key, axis=axis)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 1106, in _getitem_axis
return self._get_label(key, axis=axis)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 141, in _get_label
return self.obj._xs(label, axis=axis)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\generic.py", line 3585, in xs
loc = self.index.get_loc(key)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexes\base.py", line 2659, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas\_libs\index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 987, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 993, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 0
>>>
|
|