Q:

How to fill pandas dataframe with the same array

Trying to fill a pandas dataframe with an array (let's say np.zeros(200)).
If we want to fill a pandas dataframe with a value:
for col in df.columns:
    df[col].values[:] = 2

it works fine, but doing the same with:
for col in df.columns:
    df[col].values[:] = np.zeros(200)

will not work.
I don't understand why the error is thrown (could not broadcast input array X into shape Y,) since I thought I was populating each value of the dataframe individually, therefore the shape wouldn't matter in my opinion.

A:

Assuming I have an matrix of 200 rows:
df = pd.DataFrame(
    np.random.randint(1, 20,size=(200,3)),
    columns = ['one','two','three']
)
df.head()

    one two three
0   6   11  12
1   9   10  5
2   16  11  6
3   14  5   10
4   19  5   4

When placing: df [col] .values It does not refer to the column itself, it only obtains a series-to-array transformation, even more when putting [:] it is obtaining a memory copy of the obtained array.
The correct form would be:
for col in df.columns:
    df.loc[:, col] = np.zeros(200)
df.head()

    one two three
0   0.0 0.0 0.0
1   0.0 0.0 0.0
2   0.0 0.0 0.0
3   0.0 0.0 0.0
4   0.0 0.0 0.0

Assuming you want to do this work with other arrays that do not contain only zeros

