Guest User

Untitled

a guest
Jan 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. def open_csv(file, **kwargs):
  4. """
  5. Opens a CSV file using pandas, treating the first column as the index
  6. and preserving column order, which can be useful in case of rewriting to
  7. the same CSV.
  8. """
  9. df = pd.read_csv(file, index_col=0, **kwargs)
  10. col_order = open(file, 'r').readline().strip().split(",")[1:]
  11. return df[col_order]
Add Comment
Please, Sign In to add comment