GithubHelp home page GithubHelp logo

Comments (2)

philippkraft avatar philippkraft commented on September 25, 2024

424ff31 creates the from_pandas function with this code:

cmf/cmf/timetools.py

Lines 229 to 253 in 71926a8

def pandas_series_to_timeseries(cls, series, regularize='warning'):
import numpy as np
if (series.index[1:] - series.index[:-1] == series.index[1] - series.index[0]).all():
s = series
else:
if regularize:
s = series.resample(series.index[1] - series.index[0]).interpolate('time')
if regularize in ['w', 'warn', 'warning']:
from logging import warning
warning(('While converting pandas series "{n}" to cmf.timeseries, '
'data has been regularized and consists now of {o} original values '
'and {i} interpolated values').format(
n=series.name, o=series.count(), i=s.count() - series.count())
)
else:
raise ValueError('The pandas timeseries is not regular. '
'Try cmf.timeseries.from_series(series, regularize=True)'
'to allow for interpolation')
tstep = sec * (s.index[1] - s.index[0]).total_seconds()
tstart = datetime_to_cmf(s.index[0].to_pydatetime())
array = np.array(s)
return cls.from_array(tstart, tstep, array)

and attaches it to cmf.timeseries here:

timeseries.from_pandas = classmethod(pandas_series_to_timeseries)

from cmf.

philippkraft avatar philippkraft commented on September 25, 2024

Usage:

import pandas as pd
import cmf
import numpy as np
ts = cmf.timeseries.from_array(cmf.Time(),cmf.h, np.random.uniform(0,1,1000))    
pts = ts.to_pandas()                                                             
ts2 = cmf.timeseries.from_pandas(pts)                                            

from cmf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.