Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- def open_csv(file, **kwargs):
- """
- Opens a CSV file using pandas, treating the first column as the index
- and preserving column order, which can be useful in case of rewriting to
- the same CSV.
- """
- df = pd.read_csv(file, index_col=0, **kwargs)
- col_order = open(file, 'r').readline().strip().split(",")[1:]
- return df[col_order]
Add Comment
Please, Sign In to add comment