Advertisement
cjc5013

nlargest/nsmallest

Sep 16th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. #Get our data for SPY going back to 2003 and check out the last 5 rows
  2. df = get_pricing('spy', start_date = '2003-01-01', end_date = '2019-09-15', frequency = 'daily')
  3. df.tail()
  4.  
  5. #Make a new column containing daily percent changes
  6. df['1_day_percent_change'] = df['price'].pct_change()
  7. df.tail()
  8.  
  9. #Grab our new "1_day_percent_change" column and grab the
  10. #5 largest daily percentage increases
  11. df['1_day_percent_change'].nlargest(5)
  12.  
  13. #Grab our new "1_day_percent_change" column and grab the
  14. #5 smallest daily percentage increases
  15. df['1_day_percent_change'].nsmallest(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement