How can i count the number of words in a cell?

Looooouuuu
Looooouuuu Registered Posts: 1

Hello,

I'm looking at a list of song names and want to be able to have a column with the number of words in the song titles.

For example: Take me Home = 3 words

Please help, thank you!

Answers

  • Miguel Angel
    Miguel Angel Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 118 Dataiker
    edited July 17

    Hi,

    There is no processor or visual recipe in DSS that does exactly that. Nevertheless, you can use pandas in a python script:

    import pandas as pd
    # Sample list of song names
    song_names = [
        "Take me Home",
        "Bohemian Rhapsody",
        "Hotel California",
        "Yesterday",
        "Shape of You",
        "Stairway to Heaven"
    ]
    # Create a DataFrame with the list of song names
    df = pd.DataFrame({'Song Name': song_names})
    # Count the number of words in each song title and add as a new column
    df['Word Count'] = df['Song Name'].str.split().str.len()
    # Display the DataFrame
    print(df)
  • AmandaM
    AmandaM Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 9 Dataiker

    You can also do this visually by using two steps in a prepare recipe.

    1. Use the Tokenize text processor to split your text column into an array of words
    2. Use a formula step and add the arrayLen(tokenize_text_column) function to get the length of your array
Setup Info
    Tags
      Help me…