How to save dataframe with loop that produces NaN as output?

Viewed 18

I have written a function random_sample() where the output is a large dataframe with 2 row and 751 rows. Every time I run the function there is a novel data frame see below.

W_332 W_333 W_334 ... W_1066 W_1067 W_1068 W_1069
0 0.098432 0.094451 0.096085 ... 0.090937 0.068576 0.085326 0.095416
1 0.164170 0.197848 0.161228 ... 0.272259 0.283551 0.229989 0.230067
[2 rows x 751 columns]

When I run the following code

    for g in range(5):
    sample = random_sample()
    ref = {g:sample}
    empt_dict.append(ref)
df_pd = pd.DataFrame(empt_dict)
df_pd

I get the following table as my output but I can see all of the 5 dataframes of the above [2 rows x 751 columns] repeated with a novel set of numbers but not together

0 1 2 3 4

0 NaN NaN NaN NaN NaN

1 NaN NaN NaN NaN NaN

2 NaN NaN NaN NaN NaN

3 NaN NaN NaN NaN NaN

4 NaN NaN NaN NaN NaN

How do I save the 5 iterative 2 by 751 from my function? Thank you!

0 Answers
Related