Advertisement
RStular

Untitled

Mar 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. # CONFIG
  4. input_file_w_nuls = "data/af_daily.csv"
  5. file_wo_nuls = "data/af_daily_nn.csv"
  6. start_date = "9/11/2001" # Next time give me dates in the CSV, please
  7. resample_type = "M" # Resample to monthly periods
  8.  
  9. def remove_nul(f_in, f_out):
  10.     input = open(f_in, "rb")
  11.     data = input.read()
  12.     input.close()
  13.     output = open(f_out, "wb")
  14.     output.write(data.replace(b"\x00", b""))
  15.     output.close()
  16.  
  17. remove_nul(input_file_w_nuls, file_wo_nuls) # Don't fuck with me, NULs
  18.  
  19. af_input = pd.read_csv(file_wo_nuls, header=None) # Fuck the headers
  20.  
  21. date_index = pd.date_range(start_date, periods=len(af_input.index), freq="D") # We have daily data, hence the daily data range
  22. af_input=af_input.as_matrix(columns=None).ravel() # Convert DataFrame to numpy array
  23.  
  24. airflow_data = pd.Series(af_input, index=date_index) # Do the magic
  25.  
  26. airflow_data = airflow_data.resample(resample_type)
  27.  
  28. # ... and a whole bunch of code below here, not really important
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement