3 Replies Latest reply on Apr 2, 2018 9:39 AM by Jeff Strauss

    TabPy NLP Processing

    Raymond Rashid

      Tableau community,


      I'm working on an NLP project. I've done all the work in python, but trying to leverage the visual ability in Tableau.


      However I get an error, "Unexpected number of results returned by SCRIPT function. Function expected 42 values; 112 values were returned." I know why this is appearing as it is only trying to return one row to each row in Tableau. However, how can I force a one to many? I'm trying to leverage this into a word cloud to look at the frequency of words that are Nouns and the like.


      My TabPy Script_Str code is as below:


      "import nltk
      import pandas as pd
      import numpy as np
      from nltk.stem import WordNetLemmatizer
      from wordcloud import WordCloud, STOPWORDS


      lemmatizer = WordNetLemmatizer()
      t2 = str(t1)
      t3 = lemmatizer.lemmatize(t2)
      t4 = nltk.word_tokenize(t3)
      tagged = nltk.pos_tag(t4)
      keys = 'NN','NNP', 'NNS', 'NNPS', 'PRP', 'PRP$', 'WP'
      y = [x for x in tagged if not x in keys]
      z= pd.DataFrame(y)
      for x in c:
          if str.isalpha(x):
      o = np.unique(d)
      a = o.tolist()
      stopwords = set(STOPWORDS)
      b = [x for x in a if not x in stopwords]
      return b
      , attr([ABC]))