pd.loc 和pd.iloc区别 一个是名称索引,一个是数组索引

    1. In [152]: df = pd.DataFrame(np.random.randn(7, 3))
    2. In [153]: df
    3. Out[153]:
    4. 0 1 2
    5. 0 -1.369656 0.062440 -1.435737
    6. 1 -1.583539 1.051806 -0.942764
    7. 2 -0.483971 -1.076425 -0.249410
    8. 3 0.410681 1.496270 1.064857
    9. 4 1.486332 -0.780742 -0.270665
    10. 5 -0.550560 0.296532 -0.761322
    11. 6 -0.754117 -0.433195 0.577840
    12. In [154]: df.loc[:2] #loc 即用索引名称的end(2)是被包括进去的
    13. Out[154]:
    14. 0 1 2
    15. 0 -1.369656 0.062440 -1.435737
    16. 1 -1.583539 1.051806 -0.942764
    17. 2 -0.483971 -1.076425 -0.249410
    18. In [155]: df.iloc[:2] #iloc 即行索引的end是不包括的,和python自带语义一样
    19. Out[155]:
    20. 0 1 2
    21. 0 -1.369656 0.062440 -1.435737
    22. 1 -1.583539 1.051806 -0.942764

    df.dropna(thresh:int) 非空字段总数

    1. In [189]: df
    2. Out[189]:
    3. 0 1 2
    4. 0 NaN NaN NaN
    5. 1 NaN NaN NaN
    6. 2 NaN NaN -2.231744
    7. 3 -0.431523 NaN -0.522295
    8. 4 -1.375283 2.600212 -0.908143
    9. 5 -0.969430 0.701506 -0.962975
    10. 6 -1.350767 -1.656362 1.047282
    11. In [190]: df.dropna(thresh=1) #一列非空
    12. Out[190]:
    13. 0 1 2
    14. 2 NaN NaN -2.231744
    15. 3 -0.431523 NaN -0.522295
    16. 4 -1.375283 2.600212 -0.908143
    17. 5 -0.969430 0.701506 -0.962975
    18. 6 -1.350767 -1.656362 1.047282
    19. In [191]: df.dropna(thresh=2) #两列非空
    20. Out[191]:
    21. 0 1 2
    22. 3 -0.431523 NaN -0.522295
    23. 4 -1.375283 2.600212 -0.908143
    24. 5 -0.969430 0.701506 -0.962975
    25. 6 -1.350767 -1.656362 1.047282
    26. In [192]: df.dropna(thresh=3) #三列非空
    27. Out[192]:
    28. 0 1 2
    29. 4 -1.375283 2.600212 -0.908143
    30. 5 -0.969430 0.701506 -0.962975
    31. 6 -1.350767 -1.656362 1.047282

    fillna