Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3.  
  4. # rename files
  5. directory = 'tripdata/'
  6. for file in os.listdir(directory):
  7. filename = os.fsdecode(file)
  8. if filename.endswith('.csv'):
  9. new_filename = filename.replace(' ','').lower().split('ci', 1)[0].strip('-').replace('-','_')
  10. os.rename(os.path.join(directory, filename), os.path.join(directory, new_filename + '.csv'))
  11.  
  12. #load into DataFrames into dfs dictionary
  13. directory = 'tripdata/'
  14. dfs = {}
  15.  
  16. for file in os.listdir(directory):
  17. filename = os.fsdecode(file)
  18. if filename.endswith('.csv'):
  19. dfs[filename.split('.')[0]] = pd.read_csv(os.path.join(directory, filename))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement