14_nan.py 689 B

1234567891011121314151617181920
  1. # View more python tutorials on my Youtube and Youku channel!!!
  2. # Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
  3. # Youku video tutorial: http://i.youku.com/pythontutorial
  4. """
  5. Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
  6. """
  7. from __future__ import print_function
  8. import pandas as pd
  9. import numpy as np
  10. dates = pd.date_range('20130101', periods=6)
  11. df = pd.DataFrame(np.arange(24).reshape((6,4)), index=dates, columns=['A', 'B', 'C', 'D'])
  12. df.iloc[0,1] = np.nan
  13. df.iloc[1,2] = np.nan
  14. print(df.dropna(axis=0, how='any')) # how={'any', 'all'}
  15. print(df.fillna(value=0))
  16. print(pd.isnull(df))