Advertisement
elena1234

pandas.Series in Python

Apr 18th, 2022
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. names = ['USA', 'Canada', 'UK']
  4. years = [1992,1834,1999]
  5. names_with_years = pd.Series(data = years, index = names)
  6.  
  7. print(names_with_years['USA'])
  8. print(names_with_years['Canada'])
  9. print(names_with_years['UK'])
  10. print(names_with_years[0])
  11. print(names_with_years[1])
  12. print(names_with_years[2])
  13.  
  14. my_dict = {'cat':20, 'dog':10, 'lion':3}
  15. print(pd.Series(my_dict))
  16. print(names_with_years.keys())
  17.  
  18. names1 = ['Bulgaria', 'Canada', 'UK']
  19. years1 = [2003,2005,2003]
  20. names1_with_years = pd.Series(data = years1, index = names1)
  21.  
  22. print(names1_with_years.add(names1_with_years, fill_value = 0))
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement