Advertisement
elena1234

DataFrame with Pandas in Python

Apr 18th, 2022 (edited)
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. # 1
  4. points = [10000, 20000, 4000, 5000]
  5. names = ['Andrew', 'Maria', 'Ana', 'George']
  6. my_data = list(zip(names, points))
  7. rows = ['Canada', 'Bulgaria', 'UK', 'Belgium']
  8. cols = ['HR', 'Points']
  9. df = pd.DataFrame(data = my_data, columns = cols, index = rows)
  10. print(df)
  11.  
  12. # 2
  13. my_new_data = [['Andrew', 10000], ['Maria', 20000], ['Ana', 4000],['George',5000]]
  14. new_df = pd.DataFrame(data = my_new_data, columns = cols, index = rows)
  15. print(new_df)
  16.  
  17. # 3
  18. my_df1 = pd.read_csv('C:/Users/eli/Desktop/listings.csv')
  19. print(my_df1.head(100))
  20. print(my_df1.tail(100))
  21. print(my_df1.columns)
  22. print(my_df1.index)
  23. print(my_df1.info())
  24.  
  25. colums = ['id', 'name']
  26. print(my_df1[colums]) # grab the colums
  27.  
  28. print(my_df1.iloc[0]) # grab the first row based on integer index
  29. print(my_df1.iloc[0:4]) # grab the first four row
  30. # print(my_df1.loc['...']) # grab the first row based on label index
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement