MY CODE:
df=pd.DataFrame(columns=["a","b"], index=np.arange(1,3))
for col in df.columns:
df[col].values[:]=[[]*2]
print(df)
for col,n in enumerate(df.columns):
for row in range(1,3):
df[n][row].append([1,2,3])
print(df)
OUTPUT:
a b
1 [] []
2 [] []
0 a
a b
1 [[1, 2, 3]] []
2 [[1, 2, 3]] []
0 a
a b
1 [[1, 2, 3], [1, 2, 3]] []
2 [[1, 2, 3], [1, 2, 3]] []
1 b
a b
1 [[1, 2, 3], [1, 2, 3]] [[1, 2, 3]]
2 [[1, 2, 3], [1, 2, 3]] [[1, 2, 3]]
1 b
a b
1 [[1, 2, 3], [1, 2, 3]] [[1, 2, 3], [1, 2, 3]]
2 [[1, 2, 3], [1, 2, 3]] [[1, 2, 3], [1, 2, 3]]
I want output as the list added to all the cells. But instead the list being added to a cell, it is being added to each row of the column. Please help. Thank you in advance.
Suggested output:
a b
1 [] []
2 [] []
0 a
a b
1 [[1,2,3]] []
2 [] []
0 a
a b
1 [[1,2,3]] []
2 [[1,2,3]] []
1 b
a b
1 [[1,2,3]] [[1,2,3]]
2 [[1,2,3]] []
1 b
a b
1 [[1,2,3]] [[1,2,3]]
2 [[1,2,3]] [[1,2,3]]