Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. SOURCE CODE:
  2.  
  3. *Please follow the comments to better understand the code.
  4.  
  5. **Please look at the Screenshot below and use this code to copy-paste.
  6.  
  7. ***The code in the below screenshot is neatly indented for better understanding.
  8.  
  9.  
  10. import pandas as pd
  11.  
  12. pd.set_option('display.max_columns', None)
  13.  
  14. # read filename
  15. filename = input('Enter a file name: ')
  16. # open file
  17. with open(filename) as file:
  18. # Create a data frame
  19. df = pd.read_csv(file)
  20. # get only the columns required
  21. sub_df = df[['mpg', 'horsepower', 'model_year', 'name']]
  22. # print the sub data frame
  23. print('Last 5 rows of columns mpg, horsepower, model_year, and name:')
  24. print(sub_df.tail(5))
  25.  
  26. http://prntscr.com/pyrsfs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement