My initial dataframe looks as follows:
import pandas as pd
df = pd.DataFrame({
"id":[1,1,1,1,2,2],
"time": [1,2,3,4,5,6],
"x": [1,2,3,4,9,11 ],
"y": [5,6,7,8,3,2],
})
So I have two IDs (1 and 2) or two different time series. Now I want to add some random noise to x- and y-value for each ID and save it as new IDs (with same length) in the initial df:
# Noise
import numpy as np
noise = np.random.normal(0,1,#number of elements you get in array noise)
new_signal = original + noise
# https://stackoverflow.com/questions/14058340/adding-noise-to-a-signal-in-python
So the resulting df would look something like the following (the values are just an example what the resulting output could be):
df = pd.DataFrame({
"id":[1,1,1,1,2,2 ,3,3,3,3, 4,4],
"time": [1,2,3,4,5,6 ,7,8,9,10, 11,12 ],
"x": [1,2,3,4,9,11, 1.0005,2.3256,3.1256,4.5647, 9.6514,11.4567 ],
"y": [5,6,7,8,3,2, 5.0505,6.0276,7.1056,8.5607, 3.6014,2.4567],
})
As you can see: 2 new IDs (3 and 4) have been added and also the values with noise.
Currently I am trying it with different loops but it seems quite complicated. Any suggestions?
Bonus question: How not just duplicate, but adding it by 3 times.