pd.loc 和pd.iloc区别 一个是名称索引,一个是数组索引
In [152]: df = pd.DataFrame(np.random.randn(7, 3))In [153]: dfOut[153]:0 1 20 -1.369656 0.062440 -1.4357371 -1.583539 1.051806 -0.9427642 -0.483971 -1.076425 -0.2494103 0.410681 1.496270 1.0648574 1.486332 -0.780742 -0.2706655 -0.550560 0.296532 -0.7613226 -0.754117 -0.433195 0.577840In [154]: df.loc[:2] #loc 即用索引名称的end(2)是被包括进去的Out[154]:0 1 20 -1.369656 0.062440 -1.4357371 -1.583539 1.051806 -0.9427642 -0.483971 -1.076425 -0.249410In [155]: df.iloc[:2] #iloc 即行索引的end是不包括的,和python自带语义一样Out[155]:0 1 20 -1.369656 0.062440 -1.4357371 -1.583539 1.051806 -0.942764
df.dropna(thresh:int) 非空字段总数
In [189]: dfOut[189]:0 1 20 NaN NaN NaN1 NaN NaN NaN2 NaN NaN -2.2317443 -0.431523 NaN -0.5222954 -1.375283 2.600212 -0.9081435 -0.969430 0.701506 -0.9629756 -1.350767 -1.656362 1.047282In [190]: df.dropna(thresh=1) #一列非空Out[190]:0 1 22 NaN NaN -2.2317443 -0.431523 NaN -0.5222954 -1.375283 2.600212 -0.9081435 -0.969430 0.701506 -0.9629756 -1.350767 -1.656362 1.047282In [191]: df.dropna(thresh=2) #两列非空Out[191]:0 1 23 -0.431523 NaN -0.5222954 -1.375283 2.600212 -0.9081435 -0.969430 0.701506 -0.9629756 -1.350767 -1.656362 1.047282In [192]: df.dropna(thresh=3) #三列非空Out[192]:0 1 24 -1.375283 2.600212 -0.9081435 -0.969430 0.701506 -0.9629756 -1.350767 -1.656362 1.047282
fillna
