Create Sample Time Series Data in Python (DateTime)
I’ve been playing around with time series data in Python and was
looking for an easy and clean way to create random samples of
datetime
objects.
There’s more than one way to do this, but I was particularly fond of
an approach using the faker
library, which is outlined on
StackOverflow
here.
Code Example
First, we’ll import the faker
library and instantiate an Faker
object to generate random samples.
import faker
fake = Faker()
Then, we can test out creating a sample datetime
like so:
fake.date_time_between(start_date='-10y', end_date='now')
# datetime.datetime(2014, 10, 1, 6, 58, 47)
Or, if we want just a date
object, we can do that too:
fake.date_between(start_date='today', end_date='+10y')
# datetime.date(2023, 2, 22)
Now, if we want a range of samples, we can use Python’s array creation syntax:
datetimes = [fake.date_time_between(start_date='-30y', end_date='now') for i in range(5)]
datetimes
# Output:
# [datetime.datetime(2008, 12, 2, 15, 0, 5),
# datetime.datetime(2006, 4, 14, 12, 44, 6),
# datetime.datetime(2019, 10, 1, 17, 45, 42),
# datetime.datetime(2009, 9, 25, 15, 22, 49),
# datetime.datetime(2001, 3, 6, 8, 10, 3)]
Archive
chinese
tang-dynasty-poetry
李白
python
王维
rl
pytorch
numpy
emacs
杜牧
spinningup
networking
deep-learning
贺知章
白居易
王昌龄
杜甫
李商隐
tips
reinforcement-learning
macports
jekyll
骆宾王
贾岛
孟浩然
xcode
time-series
terminal
regression
rails
productivity
pandas
math
macosx
lesson-plan
helicopters
flying
fastai
conceptual-learning
command-line
bro
黄巢
韦应物
陈子昂
王翰
王之涣
柳宗元
杜秋娘
李绅
张继
孟郊
刘禹锡
元稹
youtube
visdom
system
sungho
stylelint
stripe
softmax
siri
sgd
scipy
scikit-learn
scikit
safari
research
qtran
qoe
qmix
pyhton
poetry
pedagogy
papers
paper-review
optimization
openssl
openmpi
nyc
node
neural-net
multiprocessing
mpi
morl
ml
mdp
marl
mandarin
macos
machine-learning
latex
language-learning
khan-academy
jupyter-notebooks
ios-programming
intuition
homebrew
hacking
google-cloud
github
flashcards
faker
docker
dme
deepmind
dec-pomdp
data-wrangling
craftsman
congestion-control
coding
books
book-review
atari
anki
analogy
3brown1blue
2fa