Support
Quality
Security
License
Reuse
kandi has reviewed motif and discovered the below as its top functions. This is intended to give you an instant insight into motif implemented functionality, and help decide if they suit your requirements.
Get all kandi verified functions for this library.
Get all kandi verified functions for this library.
Scala-like pattern matching for Java 8
QUESTION
Create a list that represents all the possible paths an individual can take
Asked 2021-Jun-01 at 12:41The below dataframe represents presumed residence of a set of individuals:
import pandas as pd
df = pd.DataFrame({'PRESUMED_RESIDENCE':['SJDR1', 'LD1', 'LD2', 'TR1', 'TR2', 'SVM']})
df
I need to create a list that contains all the possible trajectories that an individual can take - here I will call these trajectories motifs -. Below is an example of the list I expect as a final result:
MOTIFS = [[SJDR1],[LD1],[LD2], [TR1], [TR2], [SVM], [SJDR1,LD1], [SJDR1,LD2], [SJDR1,TR1],
[SJDR1,TR2], [SJDR1,SVM], [SJDR1, TR1, TR2].....[SJDR1,LD1,LD2,TR1,TR2,SVM]
With this list and the complete dataframe I can find patterns of mobility of individuals, seeing which trajectories are the most repeated. However, I have no idea how I can generate this list. Can anyone help?
ANSWER
Answered 2021-Jun-01 at 12:41Use more_itertools.powerset
which will result in list of tuples so convert it into list of list using map()
import more_itertools
vals = df["PRESUMED_RESIDENCE"].to_list()
out = list(more_itertools.powerset(vals))[1:]
MOTIFS = list(map(list, out))
print(MOTIFS)
>> [['SJDR1'],
['LD1'],
['LD2'],
['TR1'],
['TR2'],
['SVM'],
['SJDR1', 'LD1'],
['SJDR1', 'LD2'],
['SJDR1', 'TR1'],
['SJDR1', 'TR2'],
['SJDR1', 'SVM'],
['LD1', 'LD2'],
['LD1', 'TR1'],
['LD1', 'TR2'],
['LD1', 'SVM'],
['LD2', 'TR1'],
['LD2', 'TR2'],
['LD2', 'SVM'],
['TR1', 'TR2'],
['TR1', 'SVM'],
['TR2', 'SVM'],
['SJDR1', 'LD1', 'LD2'],
['SJDR1', 'LD1', 'TR1'],
['SJDR1', 'LD1', 'TR2'],
['SJDR1', 'LD1', 'SVM'],
['SJDR1', 'LD2', 'TR1'],
['SJDR1', 'LD2', 'TR2'],
['SJDR1', 'LD2', 'SVM'],
['SJDR1', 'TR1', 'TR2'],
['SJDR1', 'TR1', 'SVM'],
['SJDR1', 'TR2', 'SVM'],
['LD1', 'LD2', 'TR1'],
['LD1', 'LD2', 'TR2'],
['LD1', 'LD2', 'SVM'],
['LD1', 'TR1', 'TR2'],
['LD1', 'TR1', 'SVM'],
['LD1', 'TR2', 'SVM'],
['LD2', 'TR1', 'TR2'],
['LD2', 'TR1', 'SVM'],
['LD2', 'TR2', 'SVM'],
['TR1', 'TR2', 'SVM'],
['SJDR1', 'LD1', 'LD2', 'TR1'],
['SJDR1', 'LD1', 'LD2', 'TR2'],
['SJDR1', 'LD1', 'LD2', 'SVM'],
['SJDR1', 'LD1', 'TR1', 'TR2'],
['SJDR1', 'LD1', 'TR1', 'SVM'],
['SJDR1', 'LD1', 'TR2', 'SVM'],
['SJDR1', 'LD2', 'TR1', 'TR2'],
['SJDR1', 'LD2', 'TR1', 'SVM'],
['SJDR1', 'LD2', 'TR2', 'SVM'],
['SJDR1', 'TR1', 'TR2', 'SVM'],
['LD1', 'LD2', 'TR1', 'TR2'],
['LD1', 'LD2', 'TR1', 'SVM'],
['LD1', 'LD2', 'TR2', 'SVM'],
['LD1', 'TR1', 'TR2', 'SVM'],
['LD2', 'TR1', 'TR2', 'SVM'],
['SJDR1', 'LD1', 'LD2', 'TR1', 'TR2'],
['SJDR1', 'LD1', 'LD2', 'TR1', 'SVM'],
['SJDR1', 'LD1', 'LD2', 'TR2', 'SVM'],
['SJDR1', 'LD1', 'TR1', 'TR2', 'SVM'],
['SJDR1', 'LD2', 'TR1', 'TR2', 'SVM'],
['LD1', 'LD2', 'TR1', 'TR2', 'SVM'],
['SJDR1', 'LD1', 'LD2', 'TR1', 'TR2', 'SVM']]
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
See Similar Libraries in
Save this library and start creating your kit
Open Weaver – Develop Applications Faster with Open Source