ValueError: The truth value ...
Hi Folks,
I'm having an issue with a Python tile in Magic ETL , the code works on my machine (pycharm) but throws an error once in Domo (this happens often, what's the difference?)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.al
The goal is to produce a string value surfacing the differences between two strings, which column the difference has come from, and the position of the differences within the columns.
I define a function that achieves this, then use this function in a loop, iterating through the values in two DataFrame columns, extracting the differences, and replacing a temp DataFrame's values with these outputs.
# imports
import the domomagic package into the script from domomagic import *
import pandas as pd # read data from inputs into a data frame df = read_dataframe('Filter Rows') # Function def char_position(d,p):
z = set(d)
y = set(p)
zy_diff = z.symmetric_difference(y)
list_set = list(zy_diff)
l_2 = []
for x in range(len(zy_diff)):
try:
l_2.append(f'"{list_set[x]}" - Column_One - position {d.index(list_set[x])+1} ')
except:
pass
try:
l_2.append(f'"{list_set[x]}" - Column_Two - position {p.index(list_set[x])+1}')
except:
pass
return l_2 # Getting the original DataFrame's length weh = range(len(df.index))
# Creating a temp DataFrame using the original DataFrame's length uni = pd.DataFrame({'header':'value'},index=weh) # Executing the function against to DataFrame columns # and replacing the temp values in the temp DataFrame for x in weh:
ide = str(df['Column_One'][x]).split()
pjr = str(df['Column_Two'][x]).split()
uni.iloc[x] = [char_position(ide,pjr)] write_dataframe(uni)
^ the code box is greying out everything once published - not intentional.
All help appreciated
Answers
-
Which version of python are you using locally and which version is your script using?
import sys print(sys.version)
Is it giving you a line number which is causing the error?
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
Version: 3.10.5
Full error message:
00:00:02.282 Traceback (most recent call last): 00:00:02.282 Traceback (most recent call last): 00:00:02.282 File "<stdin>", line 40, in <module> 00:00:02.282 File "/home/domo/domomagic/io.py", line 48, in write_dataframe 00:00:02.282 write_array_dict(d) 00:00:02.283 File "/home/domo/domomagic/io.py", line 69, in write_array_dict 00:00:02.283 write_lenstrings(path, a) 00:00:02.283 File "/home/domo/domomagic/lenstrings.py", line 22, in write_lenstrings 00:00:02.283 _write_string(f, s) 00:00:02.283 File "/home/domo/domomagic/lenstrings.py", line 41, in _write_string 00:00:02.283 if pd.isnull(value): 00:00:02.283 ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
0
Categories
- All Categories
- Product Ideas
- 2.1K Ideas Exchange
- Connect
- 1.3K Connectors
- 309 Workbench
- 7 Cloud Amplifier
- 10 Federated
- Transform
- 663 Datasets
- 119 SQL DataFlows
- 2.3K Magic ETL
- 823 Beast Mode
- Visualize
- 2.6K Charting
- 86 App Studio
- 46 Variables
- Automate
- 193 Apps
- 483 APIs & Domo Developer
- 87 Workflows
- 23 Code Engine
- AI and Machine Learning
- 23 AI Chat
- 4 AI Projects and Models
- 18 Jupyter Workspaces
- Distribute
- 117 Domo Everywhere
- 283 Scheduled Reports
- 11 Software Integrations
- Manage
- 143 Governance & Security
- 11 Domo Community Gallery
- 49 Product Releases
- 13 Domo University
- Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 116 Community Announcements
- 5K Archive