random - Python generate data based on archives -


i'm working on operations research project.

i created heuristic method , need test method intensively assess performance.

i have past data, in form of 3 fields;

date, amount, type

what want generate new data, similar the existing data. i'm doing "+/- random".

i there method or lib generate original data, similar existing data analysing statistics , trends of old data.

per comment, can use pandas. example, first generate dummy data:

data = [{'date': 'dummy', 'amount':1, 'type': 'a'},         {'date': 'dummy' , 'amount':2, 'type': 'a'},         {'date': 'dummy', 'amount':1, 'type': 'b'},         {'date': 'dummy', 'amount':1, 'type': 'b'},         {'date': 'dummy', 'amount':2, 'type': 'c'}] 

import appropriate libraries:

import pandas pd import random 

import data pandas dataframe:

df = pd.dataframe(data, columns=['date', 'amount', 'type']) 

output:

    date  amount type 0  dummy       1    1  dummy       2    2  dummy       1    b 3  dummy       1    b 4  dummy       2    c 

then apply random "+/-" data method:

df['new  amount'] = df['amount'].apply(lambda amount: amount + (-random.random())**random.randint(1, 2)) 

results:

    date  amount type  new  amount 0  dummy       1        1.021583 1  dummy       2        1.496697 2  dummy       1    b     0.685394 3  dummy       1    b     1.764432 4  dummy       2    c     2.219713 

of course process have changed based on exact needs. can used pandas statistical analysis come other methods transform data.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -