-
-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Closed
Labels
EnhancementReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, Explode
Description
Is your feature request related to a problem?
This seems to be kind of a niche issue, but I found myself needing to do this operation to format data in a way that an SQL table ARRAY structure would accept it using the pandas.to_sql function (in conjunction with sqlalchemy).
Describe the solution you'd like
The set of operations needed is described in this stackoverflow post: https://stackoverflow.com/questions/64235312/how-to-implodereverse-of-pandas-explode-based-on-a-column
Example:
df:
NETWORK config_id APPLICABLE_DAYS
0 Grocery 5399 SUN
1 Grocery 5399 MON
2 Grocery 5399 TUE
3 Grocery 5399 WED
df.implode('APPLICABLE_DAYS')
NETWORK config_id APPLICABLE_DAYS
0 Grocery 5399 SUN,MON,TUE,WED
The set of operations actual used were the following:
df = (df.groupby(['NETWORK','config_id'])
.agg({'APPLICABLE_DAYS': lambda x: ",".join(x)})
.reset_index())
MichaelTiemannOSC, jbcoffin, SiggyF and RonUlitsky
Metadata
Metadata
Assignees
Labels
EnhancementReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, Explode