skip to Main Content

I trying to scrape data from twitter following the examples from this page: https://www.earthdatascience.org/courses/use-data-open-source-python/intro-to-apis/twitter-data-in-python/

        # -*- coding: cp852 -*-
    import sys
    sys.modules[__name__].__dict__.clear()
    
    import os
    import tweepy as tw
    import pandas as pd
    
    consumer_key = 'XXX'
    consumer_secret = 'YYY'
    access_token = 'ZZZ'
    access_token_secret = 'BBB'
    print(consumer_key)
    
    auth = tw.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    api = tw.API(auth, wait_on_rate_limit=True)
    
    
    
    
    # Define the search term and the date_since date as variables
    search_words = "#MERZ"
    date_since = "2021-01-16"
    
    #Collect tweets
    
    tweets = tw.Cursor(api.search,
        q=search_words,
        lang = "en",
        since=date_since).items(5)
    
    for tweet in tweets:
        print(tweet.text.encode('cp1252', errors='ignore'))
    
    print([tweet.text for tweet in tweets])
    
    
    
    
    new_search = search_words + " -filter:retweets"
    #new_search
    
    
    tweets = tw.Cursor(api.search,
                           q=new_search,
                           lang="en",
                           since=date_since).items(5)
    
    print([tweet.text for tweet in tweets])
    
    
    
    tweets = tw.Cursor(api.search,
                               q=new_search,
                               lang="en",
                               since=date_since).items(5)
    
    users_locs = [[tweet.user.screen_name, tweet.user.location] for tweet in tweets]
    print(users_locs)
    
    
    
    
    tweet_text = pd.DataFrame(data=users_locs,
                  columns=['user', "location"])
print(tweet_text)

However, I fail to print the data frame. The error message reads as follows:

TypeError: ‘NoneType’ object is not callable

Can anyone help me. Your help is highly appreciated. Thanks.

EDIT 1: I have been asked to provide more information. Attached, you find the complete error message.

Traceback (most recent call last):
  File "C:UsersMustermannDesktoptweeptweep.py", line 59, in <module>
    print(tweet_text)
  File "C:UsersMustermannAnaconda3libsite-packagespandascoreframe.py", line 744, in __repr__
    self.to_string(
  File "C:UsersMustermannAnaconda3libsite-packagespandascoreframe.py", line 883, in to_string
    return formatter.to_string(buf=buf, encoding=encoding)
  File "C:UsersMustermannAnaconda3libsite-packagespandasioformatsformat.py", line 921, in to_string
    return self.get_result(buf=buf, encoding=encoding)
  File "C:UsersMustermannAnaconda3libsite-packagespandasioformatsformat.py", line 520, in get_result
    self.write_result(buf=f)
  File "C:UsersMustermannAnaconda3libsite-packagespandasioformatsformat.py", line 844, in write_result
    max_len = Series(lines).str.len().max()
  File "C:UsersMustermannAnaconda3libsite-packagespandascoregeneric.py", line 11459, in stat_func
    return self._reduce(
  File "C:UsersMustermannAnaconda3libsite-packagespandascoreseries.py", line 4236, in _reduce
    return op(delegate, skipna=skipna, **kwds)
  File "C:UsersMustermannAnaconda3libsite-packagespandascorenanops.py", line 120, in f
    result = bn_func(values, axis=axis, **kwds)
TypeError: 'NoneType' object is not callable
[Finished in 2.306s]

Edit 2: I seem to get the error even in a minimal example using Pandas. Please see code attached. I changed the title as well.

import pandas as pd
import numpy as np

d = {'col1': [1, 2], 'col2': [3, 4]}
print(d)
df = pd.DataFrame(data=d)

df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),

                   columns=['a', 'b', 'c'])
print(df)
print(df2)

3

Answers


  1. Chosen as BEST ANSWER

    Not sure how, but I fixed it by reinstalling Anaconda.


  2. I don’t know a fix, the problem is you’re trying to use a None object as a Function (None means nothing). The error message contains a line, which one does it show?

    Login or Signup to reply.
  3. This fixed it for me:

    pip install bottleneck -U --force-reinstall
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search