Created
October 8, 2021 01:25
-
-
Save aagontuk/14b1f1a57da9ef5bdc0ae18958faedf6 to your computer and use it in GitHub Desktop.
Resample Data
This file contains hidden or 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 | |
interval = '1min' | |
in_sheet = "sample.csv" | |
out_sheet = "output.csv" | |
# read the csv file | |
df = pd.read_csv(in_sheet) | |
print("Resampling to {0} data...".format(interval)) | |
# Merge Date and Time into datetime format | |
datetime = pd.to_datetime(df['Date'] + ' ' + df['Time']) | |
# Remove Date, Time and Comments field | |
df = df.drop(['Date', 'Time', 'Comments'], axis = 1) | |
# set datetime as the index column | |
# resample wants the index column as datetime. | |
df.index = datetime | |
df.index.name = "Datetime" | |
# resample data to 1min interval | |
df = df.resample(interval).sum() | |
print("Saved in {0}".format(out_sheet)) | |
df.to_csv(out_sheet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment