Home > database >  Creating a pandas series from multiple numpy arrays
Creating a pandas series from multiple numpy arrays

Time:01-24

If i have for instance, two numpy arrays np.full(10,1) and np.full(10,2), what is the most efficient way to create a pandas series?

Right now i would first create a pandas DataFrame and convert it into a pd.Series:

check = pd.DataFrame([np.full(10,1), np.full(10,2)])
check.transpose().unstack().reset_index(drop=True)
Out[0]: 
0     1
1     1
2     1
3     1
4     1
5     1
6     1
7     1
8     1
9     1
10    2
11    2
12    2
13    2
14    2
15    2
16    2
17    2
18    2
19    2
dtype: int64

This seem extremely inefficient though, so what is the smartest way of doing this?

CodePudding user response:

How about pd.DataFrame(np.concatenate([arr1,arr2]))

  •  Tags:  
  • Related