13_set_value.py 708 B

123456789101112131415161718192021
  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.random.randn(6,4), index=dates, columns=['A', 'B', 'C', 'D'])
  12. df.iloc[2,2] = 1111
  13. df.loc['2013-01-03', 'D'] = 2222
  14. df.A[df.A>0] = 0
  15. df['F'] = np.nan
  16. df['G'] = pd.Series([1,2,3,4,5,6], index=pd.date_range('20130101', periods=6))
  17. print(df)