Simple way to append a pandas series with same index
pandas, python
Solution
One option is to use `reset_index`:
>>> a.append(b).reset_index(drop=True)
0 -0.370406
1 0.963356
2 -0.147239
3 -0.468802
4 0.057374
5 -1.113767
6 1.255247
7 1.207368
8 -0.460326
9 -0.685425
dtype: float64
For the sake of justice, Roman Pekar method is fastest:
>>> timeit('from __main__ import np, pd, a, b; pd.Series(np.concatenate([a,b]))', number = 10000)
0.6133969540821536
>>> timeit('from __main__ import np, pd, a, b; pd.concat([a, b], ignore_index=True)', number = 10000)
1.020389742271714
>>> timeit('from __main__ import np, pd, a, b; a.append(b).reset_index(drop=True)', number = 10000)
2.2282133623128075
Problem
Is there a simple way to append a pandas series to another and update its index ? Currently i have two series ``` from numpy.random import randn from pandas import Series a = Series(randn(5)) b = Series(randn(5)) ``` and i can append `b` to `a` by ``` a.append(b) >>> 0 -0.191924 1 0.577687 2 0.332826 3 -0.975678 4 -1.536626 0 0.828700 1 0.636592 2 0.376864 3 0.890187 4 0.226657 ``` but is there a smarter way to make sure that i have a continuous index than ``` a=Series(randn(5)) b=Series(randn(5),index=range(len(a),len(a)+len(b))) a.append(b) ```