t.py 869 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # !/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. '''
  4. @Auther :liuyuqi.gov@msn.cn
  5. @Time :2018/7/8 3:16
  6. @File :t.py
  7. '''
  8. import pandas as pd
  9. def t1():
  10. # list
  11. cpuIter = list()
  12. for i in range(10):
  13. cpuIter.append(i)
  14. print(cpuIter)
  15. def t2():
  16. # dict
  17. res = list()
  18. n = 5
  19. for i in range(n):
  20. res.append({})
  21. res[1] = {"A": 2, "B": 3}
  22. res.append({"appid": 0})
  23. print(res[1].get("C") == None)
  24. print(res)
  25. def t3():
  26. # pandas dataframe
  27. result = pd.DataFrame(columns=list(["instanceid", "machineid"]), data=list())
  28. for i in range(5):
  29. # result = result.append(pd.DataFrame(
  30. # [{"instanceid": "2",
  31. # "machineid": "machine_" + str(2)}]))
  32. result = result.append(
  33. [{"instanceid": "2",
  34. "machineid": "machine_" + str(2)}])
  35. print(result)
  36. t2()