I have a dataframe in Pandas with duplicate values in Col1:
| Col1 |
|---|
| a |
| a |
| b |
| a |
| a |
| b |
What I want to do is to split this df into different df-s with unique Col1 values in each.
DF1:
| Col1 |
|---|
| a |
| b |
DF2:
| Col1 |
|---|
| a |
| b |
DF3:
| Col1 |
|---|
| a |
DF4:
| Col1 |
|---|
| a |
Any suggestions ?
I have a dataframe in Pandas with duplicate values in Col1:
| Col1 |
|---|
| a |
| a |
| b |
| a |
| a |
| b |
What I want to do is to split this df into different df-s with unique Col1 values in each.
DF1:
| Col1 |
|---|
| a |
| b |
DF2:
| Col1 |
|---|
| a |
| b |
DF3:
| Col1 |
|---|
| a |
DF4:
| Col1 |
|---|
| a |
Any suggestions ?
Copyright © 2021 Jogjafile Inc.
I don't think you can achieve this in a vectorial way.
One possibility is to use a custom function to iterate the items and keep track of the unique ones. Then use this to split with
groupby:output:
intermediate:
if order doesn't matter
Let's ad a Col2 to the example:
the previous code gives:
If order does not matter, you can vectorize it:
output: