Python, Update the shape of an array with set values at new indexes based on the update of another array's shape
I have a pandas.DataFrame which contains 2 columns, x and y. The record type for each is a numpy.array. I want to update both x and y based on the new positions added in x.
All records in x column are same and look like:
array([14., 16., 18., 20., 22.,
24., 26., 28., 30., 32.])
A record in y column looks like:
array([18.71003688, 46.34225223, 62.85395246, 54.6278999 , 44.90160129,
47.15627018, 59.44501392, 49.35773708, 40.35890602, 17.20255624])
The question here is if I were to update the x column with this (Update to x will only be in the beginning or the end):
array([10., 12., 14., 16., 18.,
20., 22., 24., 26., 28.,
30., 32., 34., 36., 38.,
40.])
I want to update the record in y column to have 10.00 in all the new indexes:
array([10.00, 10.00, 18.71, 46.34, 62.85,
54.62, 44.90, 47.15, 59.44, 49.35,
40.35, 17.20, 10.00, 10.00, 10.00,
10.00])
@richardec:
df.head().to_dict():
{'x': {0: array([14., 16., 18., 20., 22., 24., 26., 28., 30., 32.]),
1: array([14., 16., 18., 20., 22., 24., 26., 28., 30., 32.]),
2: array([14., 16., 18., 20., 22., 24., 26., 28., 30., 32.]),
3: array([14., 16., 18., 20., 22., 24., 26., 28., 30., 32.]),
4: array([14., 16., 18., 20., 22., 24., 26., 28., 30., 32.])},
'y': {0: array([18.61569528, 23.53634178, 58.36532315, 77.54198597, 28.0641304 ,
65.30746286, 37.23019412, 41.33584277, 32.32958567, 76.2471661 ]),
1: array([65.00116509, 55.75035838, 24.0169996 , 65.52242193, 18.68593464,
41.99858577, 41.04883184, 24.28772448, 79.46411667, 58.41317359]),
2: array([51.01619179, 48.9177941 , 34.77544541, 35.74428367, 39.83933452,
42.68396121, 33.37758827, 58.15300226, 66.08925208, 21.33814375]),
3: array([73.17915777, 32.2479716 , 63.22276059, 19.30288733, 37.25751032,
27.2461532 , 30.30136879, 78.89398042, 16.11675921, 62.49085551]),
4: array([43.4760009 , 41.53331501, 29.44308989, 23.66155076, 46.83107104,
79.15013693, 67.77324069, 74.50343753, 48.71949902, 38.86433951])}}
source https://stackoverflow.com/questions/71023732/python-update-the-shape-of-an-array-with-set-values-at-new-indexes-based-on-the
Comments
Post a Comment