Survey banner
The Dataiku Community is moving to a new home! We are temporary in read only mode: LEARN MORE

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

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

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!

0 Kudos
2 Replies
MiguelangelC
Dataiker

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)
0 Kudos
AmandaM
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