This is my initial data frame df
:
col1 col2 col3
1 0.5 10
1 0.3 11
5 1.4 1
3 1.5 2
1 0.9 10
3 0.4 7
1 1.2 9
3 0.1 11
4 0.1 11
I converted it into a list of data frames list_df
:
n = 3 # the value of "n" does not matter
list_df = [df[i:i+n] for i in range(0, df.shape[0],n)]
list_df
[
pd.DataFrame(
col1 col2 col3
1 0.5 10
1 0.3 11
5 1.4 1),
pd.DataFrame(
col1 col2 col3
3 1.5 2
1 0.9 10
3 0.4 7),
pd.DataFrame(
col1 col2 col3
1 1.2 9
3 0.1 11
4 0.1 11)
]
How can I randomly split this list into two lists of data frames: list_df1
and list_df2
, so that list_df1
would contain 70% of lists of data frames, and list_df2
would contain the rest.
I tried to use masking, but it does not work with a list of data frames.