Skip to content

Instantly share code, notes, and snippets.

@yassineAlouini
Created October 4, 2018 08:20
Show Gist options
  • Save yassineAlouini/e67851bcc78036d4ea239a9b0d11829d to your computer and use it in GitHub Desktop.
Save yassineAlouini/e67851bcc78036d4ea239a9b0d11829d to your computer and use it in GitHub Desktop.
Break a (large) CSV file into various ones per year.
import pandas as pd
INPUT_PATH = "your/input/path.csv"
OUPUT_PATH = "your/output/path_{}.csv"
df = pd.read_csv(INPUT_PATH, parse_dates=['tms_gmt'])
df['year'] = df.tms_gmt.dt.year
for year in df['year'].unique():
df.loc[lambda df: df.year == year].to_csv(OUPUT_PATH.format(year), index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment