I feel like this is a super simple question, I just don't have the vocabulary to articulate it in google. Here goes:
I have a dataframe that I want to slice and split into several dataframe. So I created a function and a for loop for this.
Sample table
col1 col2 col3 col4 col5
row1 A Hi my name is
row2 A Bye see you later
row3 B Bike on side walk
row4 B Car on str drive
row5 C Dog on grs poop
My code is like this
list_ = list(df['col1'].drop_duplicates())
for i in list_:
dataframe_creator(i)
My function list this
def dataframe_creator(i):
df = df[df['col1'] == i]
return df
So the results of this is that it just creates a dataframe for slice and then assigns it to the same variable which isn't what I want, I want a variable for each iteration. Basically I'd like to have 3 dataframe labelled dfA, dfB, dfC at the end that holds each slice.