Answers for "append numpy array to dataframe row"

1

how to append rows to a numpy matrix

import numpy as np    
arr = np.empty((0,3), int)
print("Empty array:")
print(arr)
arr = np.append(arr, np.array([[10,20,30]]), axis=0)
arr = np.append(arr, np.array([[40,50,60]]), axis=0)
print("After adding two new arrays:")
print(arr)
Posted by: Guest on June-28-2021
2

add numpy array to pandas dataframe

#create NumPy array for 'blocks'
blocks = np.array([2, 3, 1, 0, 2, 7, 8, 2])

#add 'blocks' array as new column in DataFrame
df['blocks'] = blocks.tolist()
Posted by: Guest on August-29-2021

Python Answers by Framework

Browse Popular Code Answers by Language