You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, this would create new column "file_type" that has the values "image" and "motion" depending on whether the path in the filepath column contains ".nii" or ".txt":
# add info if files is image or motion files
pattern_dict = {".nii": "image", ".txt": "motion"}
df['file_type'] = df['filepath'].apply(
lambda path: [val for key, val in pattern_dict.items() if key in path][0])
Would be nice if one could also make this work with regexes. The following code goes already in the right direction but it will only replace the found match with the value:
# Create a new column based on pattern matching
pattern_dict = {r'^.nii$': 'image', r'^.txt$': 'motion'}
df['file_type'] = df['filepath'].replace(pattern_dict, regex=True)
https://stackoverflow.com/questions/68869434/create-an-pandas-column-if-a-string-from-a-list-matches-from-another-column
The text was updated successfully, but these errors were encountered: