我正在做一个项目,我必须处理很多诊断。无论目的是什么,在编码方面,我认为下面的代码是正确的,但是它需要花费很多时间(〜1小时),并且它总是向我显示警告。有什么是我做对了吗?提前感谢您
# The first 3 values are the only that matters
diagnoses_sec = df[['Diagnóstico 2', 'Diagnóstico 3', 'Diagnóstico 4', 'Diagnóstico 5', 'Diagnóstico 6',
'Diagnóstico 7', 'Diagnóstico 8', 'Diagnóstico 9', 'Diagnóstico 10', 'Diagnóstico 11', 'Diagnóstico 12',
'Diagnóstico 13', 'Diagnóstico 14', 'Diagnóstico 15', 'Diagnóstico 16', 'Diagnóstico 17', 'Diagnóstico 18',
'Diagnóstico 19', 'Diagnóstico 20']]
for i in range(0, diagnoses_sec.shape[1]):
diagnoses_sec.iloc[:,i].fillna("ZZZ", inplace = True)
diagnoses_sec.iloc[:,i] = diagnoses_sec.iloc[:,i].str.slice(start=0, stop=3, step=1)
在这一部分中,有一个警告,但我不明白为什么:
C:\Users\Asus\Anaconda3\lib\site-packages\pandas\core\indexing.py:630: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
self.obj[item_labels[indexer[info_axis]]] = value
代码的第二部分是:
from bisect import bisect_left
diag_icd10_ranges = ["B99","D49","D89","E89","F99","G99","H59","H95",
"I99","J99","K95", "L99", "M99", "N99","O9A","P96","Q99",
"R99","T88","Y99","Z99","ZZZ"]
Qyouu
相关分类