winwin winwin - 10 months ago 228
Python Question

Append Numpy ndarray to pandas dataframe

I have ten numpy ndarrys each having one row and 100 columns. Now I want to append them sequentially to a pandas dataframe (should have 10 rows and 100 columns in the end). How can I achieve that in python:

# create empty dataframe
data = pd.DataFrame()

# Loop
for i in range(1, 11):

# Simulate ndarrys
one_row = np.array([range(1, 101)])

# Trying to append
data = data.append(data, one_row)


Create iteratively the array, to make it 10x100, then pass it to DataFrame.

You can use np.insert or np.vstack to create the 10x100 array.