Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 51 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. import pandas as pd
  2. from tkinter import filedialog
  3. from tkinter import Tk
  4.  
  5.  
  6.  
  7. def wecc_sort():
  8.    
  9.     # This prompts you to pick a file (a csv) that you want to filter
  10.     Tk().withdraw()
  11.     pickled_ahead = filedialog.askopenfilename()
  12.  
  13.     # This reads in the file and tells you that it is loading
  14.     print('Loading file...')
  15.     df = pd.read_csv(pickled_ahead)
  16.  
  17.     # This filters the dataframe by the Buyer Ownership Type. Right now it's set to "not equal to private"
  18.     df = df[df['Buyer Ownership Type'] != 'Private']
  19.     # df = df[df['Buyer Ownership Type'] == 'Private'] # Whereas this one for example filters for only equal to private
  20.    
  21.     # This filters by the various parameters Rate Unit Code as $/KW OR $/MW
  22.     df = df[(df['Rate Unit Code'] == '$/KW') | (df['Rate Unit Code'] == '$/MW')]
  23.    
  24.     # This resets the index because we dropped a bunch of data and need to get rid of the empty space they left
  25.     df.reset_index(drop=True, inplace=True)
  26.    
  27.     # This creates a new dataframe with only the columns we want from the filtered dataframe
  28.     df_save = df[['Buyer Name', 'Seller Name', 'Rate Unit Code', 'Buyer Ownership Type', 'Price']]
  29.  
  30.     # This saves the new dataframe to a csv. Change the name to what you want. It will output to wherever this script
  31.     # is saved.
  32.     df_save.to_csv('WECC Sort For Zach.csv')
  33.  
  34. ### Run your functions here
  35.  
  36. wecc_sort()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top