Created
March 19, 2025 01:33
Force to list Python in Excel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def force_to_list(value): | |
if isinstance(value, pd.DataFrame): | |
return value.values.flatten().tolist() | |
elif isinstance(value, str): | |
return [value] # Wrap single string in a list | |
elif hasattr(value, '__iter__') and not isinstance(value, str): | |
return list(value) # Handle other iterable types | |
else: | |
return [value] # Wrap scalars in a list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment