Skip to content

Instantly share code, notes, and snippets.

@fxadecimal
Last active August 10, 2020 17:10
Show Gist options
  • Save fxadecimal/137eb404628ebf0176a21ae108a5128f to your computer and use it in GitHub Desktop.
Save fxadecimal/137eb404628ebf0176a21ae108a5128f to your computer and use it in GitHub Desktop.
"""
Simple Pandas demo
- generating time-series data
- writing & load with CSV
- resampling
"""
import numpy as np
import scipy
import pandas as pd
N = 1000000
start = pd.Timestamp('2015-07-01')
end = pd.Timestamp('2015-08-01')
x = np.linspace(start.value, end.value, N)
y = np.sin(x)
# convert to datatime
x = pd.to_datetime(x)
df = pd.DataFrame(dict(x=x, y=y))
df.set_index('x', inplace=True)
df.to_csv('/tmp/data.csv')
# BREAK
df = pd.read_csv('/tmp/data.csv', parse_dates=True, index_col='x')
df.index = pd.to_datetime(df.index, unit='s')
df = df.resample( '86400s' ).mean()
df.to_csv('/tmp/data_resampled.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment