cancel
Showing results for 
Search instead for 
Did you mean: 

Leveraging Python in Workato > Marketo

ecamarillo
Deputy Chef I
Deputy Chef I

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)

3 REPLIES 3

Bhagya_pola
Executive Chef I
Executive Chef I

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 clarificationScreenshot 2025-12-11 205753.png

rajeshjanapati
Executive Chef I
Executive Chef I

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)

        }

 

 

Screenshot 2025-12-11 235108.pngScreenshot 2025-12-12 001223.png

Screenshot 2025-12-12 001318.pngScreenshot 2025-12-12 001447.png

Further, if you have doubts, please keep posted, will discuss here.

Thanks & Regards,

J Rajesh Kumar.

gary1
Star Chef I
Star Chef I

Since you're new to Workato, my honest opinion is you should try to do this using native Workato actions and not Python.