-
-
Save jorgemanrubia/2abe273acbdcb31da30cde44f295cff0 to your computer and use it in GitHub Desktop.
Chat GPT prompt 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import time | |
from datetime import datetime | |
# Read the input CSV file | |
df = pd.read_csv("input.csv") | |
# Convert the first column to milliseconds from midnight | |
df['Timestamp'] = df['Timestamp'].apply(lambda x: int((datetime.strptime(x, '%Y-%m-%d %H:%M:%S') - datetime.strptime("00:00:00", '%H:%M:%S')).total_seconds() * 1000)) | |
# Split the dataframe into smaller dataframes based on the date | |
dfs = {k: v for k, v in df.groupby(df['Timestamp'].dt.date)} | |
# Write the smaller dataframes to individual CSV files | |
for date, data in dfs.items(): | |
data.to_csv(f"{date}.csv", index=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I want to create a python script to convert large CSV into individual CSV files. | |
The input file has this format: | |
2023-01-06 16:59:00,3913.50,3913.75,3913.25,3913.75,327 | |
The output file has this format: | |
82740000,3913.5,3913.75,3913.25,3913.75,327 | |
The only conversion I want to do is the first column: Instead of the date, I want the milliseconds that have happened from midnight. | |
Also, I want to split the input file into smaller files: I want to create one file per day. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment