2

Can anybody explain me why this code should not work?

wordsCount = {}

def addWord(x):
    print(x)

df.apply(addWord(x))

It return the error: TypeError: ("'NoneType' object is not callable", 'occurred at index 0') The dataframe df contains some None value in some cell. My intention is to apply a function to all non-None value.

3
  • .apply() expects a function, but you are passing it the return value by calling addWord(x), which is None, since no return value is specified in the addWord function. Just pass addWord without the parenthesis. Commented Oct 16, 2017 at 1:21
  • Ok thanks. So now I discover than with apply I can only iterate over columns. What is I want to iterate over each element of the dataframe? Commented Oct 16, 2017 at 1:33
  • pandas.pydata.org/pandas-docs/stable/generated/… Commented Oct 16, 2017 at 1:34

1 Answer 1

5

Use pandas.DataFrame.applymap

df.applymap(addWord)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.