yesterday
Greetings, fairly new to Workato and I am struggling to figure out how to leverage Python to transform data in Marketo.
I have a simple script snippet meant to fetch a list of leads whose phone number begins with a '1' and remove it.
It works in an IDLE environment but I am unsure how to enable it in Workato.
Here is the script:
import pandas as pd
# Load the CSV file
df = pd.read_csv('Test_Phone_Numbers.csv')
# Remove leading '1'
df['Phone Number'] = df['Phone Number'].astype(str).str.lstrip('1')
# Save the modified DataFrame back to CSV
df.to_csv('updated_file.csv', index=False)
print(df)
14 hours ago
Hello @ecamarillo ,
Python in Workato works different
please check the commented part in the code block for the reference and also pass your input content in the input section of the python code and access it in below code block.
see below image for better understanding, the code should be written in Workato supported format.
Please let me know if you need further clarification
11 hours ago - last edited 10 hours ago
Hi @ecamarillo,
In workato, need to define python code in different way and also calling input data or values differently, here I am attaching the python code, recipe URL. you can easily check perform your filtering.
recipeURL: Cleaning PhoneNumbers from CSV File using Python code
import pandas as pd
import io
def main(input):
try:
# Read the CSV content directly from the field Workato sends
file_content = input['input_CSV_File']
# Convert CSV text to DataFrame
toread = io.StringIO(file_content)
df = pd.read_csv(toread)
# Convert phoneNumber to string
df['phoneNumber'] = df['phoneNumber'].astype(str)
# ๐ฅ Delete rows where phoneNumber starts with "1"
df = df[~df['phoneNumber'].str.startswith('1')]
# Convert back to CSV
updated_csv = df.to_csv(index=False, header=True)
return {
'output_CSV_File': updated_csv
}
except Exception as e:
return {
'error': str(e)
}
Further, if you have doubts, please keep posted, will discuss here.
Thanks & Regards,
J Rajesh Kumar.
30m ago
Since you're new to Workato, my honest opinion is you should try to do this using native Workato actions and not Python.