<small id='qt1Su'></small><noframes id='qt1Su'>

    • <bdo id='qt1Su'></bdo><ul id='qt1Su'></ul>
    <i id='qt1Su'><tr id='qt1Su'><dt id='qt1Su'><q id='qt1Su'><span id='qt1Su'><b id='qt1Su'><form id='qt1Su'><ins id='qt1Su'></ins><ul id='qt1Su'></ul><sub id='qt1Su'></sub></form><legend id='qt1Su'></legend><bdo id='qt1Su'><pre id='qt1Su'><center id='qt1Su'></center></pre></bdo></b><th id='qt1Su'></th></span></q></dt></tr></i><div id='qt1Su'><tfoot id='qt1Su'></tfoot><dl id='qt1Su'><fieldset id='qt1Su'></fieldset></dl></div>
    <tfoot id='qt1Su'></tfoot>

        <legend id='qt1Su'><style id='qt1Su'><dir id='qt1Su'><q id='qt1Su'></q></dir></style></legend>

        解析用户名以提取用户位置 Twitter

        时间:2023-09-10
          <tbody id='Pas2h'></tbody>

        <small id='Pas2h'></small><noframes id='Pas2h'>

          1. <tfoot id='Pas2h'></tfoot>
            <legend id='Pas2h'><style id='Pas2h'><dir id='Pas2h'><q id='Pas2h'></q></dir></style></legend>
              <bdo id='Pas2h'></bdo><ul id='Pas2h'></ul>
            • <i id='Pas2h'><tr id='Pas2h'><dt id='Pas2h'><q id='Pas2h'><span id='Pas2h'><b id='Pas2h'><form id='Pas2h'><ins id='Pas2h'></ins><ul id='Pas2h'></ul><sub id='Pas2h'></sub></form><legend id='Pas2h'></legend><bdo id='Pas2h'><pre id='Pas2h'><center id='Pas2h'></center></pre></bdo></b><th id='Pas2h'></th></span></q></dt></tr></i><div id='Pas2h'><tfoot id='Pas2h'></tfoot><dl id='Pas2h'><fieldset id='Pas2h'></fieldset></dl></div>
                  本文介绍了解析用户名以提取用户位置 Twitter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试从 twitter 中获取与用户名相关的用户位置.

                  I am trying to scrape user location with respect to user names from twitter.

                  输入:用户列表有超过50K个用户名

                  Input: The user list has more than 50K User names

                  AkkiPritam,6.77E+17,12/15/2015,#chennaifloods
                  AkkiPritam,6.77E+17,12/15/2015,#bhoomikatrust
                  AkkiPritam,6.77E+17,12/15/2015,#akshaykumar
                  gischethans,6.77E+17,12/15/2015,#chennaifloods
                  mid_day,6.77E+17,12/15/2015,#bollywood
                  mid_day,6.77E+17,12/15/2015,#chennaifloods
                  Nanthivarman16,6.77E+17,12/15/2015,#admkfails
                  Nanthivarman16,6.77E+17,12/15/2015,#jayafails
                  Nanthivarman16,6.77E+17,12/15/2015,#stickergovt
                  Nanthivarman16,6.77E+17,12/15/2015,#chennaifloods
                  AdilaMatra,6.77E+17,12/15/2015,#chennaifloods
                  AdilaMatra,6.77E+17,12/15/2015,#climatechange
                  AdilaMatra,6.77E+17,12/15/2015,#delhichokes
                  AdilaMatra,6.77E+17,12/15/2015,#smog
                  HDFCERGOGIC,6.77E+17,12/15/2015,#chennaifloods
                  HDFCERGOGIC,6.77E+17,12/15/2015,#tnfloods
                  ImSoorej,6.77E+17,12/15/2015,#chennaifloods
                  ImSoorej,6.77E+17,12/15/2015,#chennaimicr
                  

                  代码:我想查找地理位置,可能是地理坐标.

                  Code: I want to find geo location possibly geo coordinates.

                  from __future__ import print_function
                  import tweepy
                  from tweepy import OAuthHandler
                  from tweepy import Stream
                  from tweepy.streaming import StreamListener
                  import pandas as pd
                  import csv
                  
                  consumer_key = 'xyz'
                  consumer_secret = 'xyz'
                  access_token = 'xyz'
                  access_token_secret = 'xyz'
                  
                  data = pd.read_csv('user_keyword.csv')
                  df = ['user_name', 'user_id', 'date', 'keyword']
                  
                  def get_user_details(username):
                          userobj = api.get_user(username)
                          return userobj
                  
                  if __name__ == '__main__':
                      #authenticating the app (https://apps.twitter.com/)
                      auth = tweepy.auth.OAuthHandler(consumer_key, consumer_secret)
                      auth.set_access_token(access_token, access_token_secret)
                      api = tweepy.API(auth)
                  
                      username = df['user_name']
                      userOBJ = get_user_details(username)
                      print(userOBJ.location)
                  

                  错误:无法将用户名解析为程序.

                  Error: Trouble parsing the usernames into program.

                  Traceback (most recent call last):
                    File "user_profile_location.py", line 38, in <module>
                      username = df['user_name']
                  TypeError: list indices must be integers, not str
                  

                  推荐答案

                  你正在使用'data'来定义你的DataFrame和'df'我认为应该是DataFrame的列

                  You are using 'data' to define your DataFrame and 'df' for what I think should be the columns of the DataFrame

                  data = pd.read_csv('user_keyword.csv')
                  df = ['user_name', 'user_id', 'date', 'keyword']
                  

                  我假设 user_keyword.csv 文件没有标题,尝试添加:

                  I assume that the user_keyword.csv file has no header, try adding:

                  data.columns = df
                  

                  它会将列名更改为存储在 df 中的值.然后稍后代替:

                  It will change the column names to the values stored in df. Then later instead of:

                  username = df['user_name']
                  

                  试试:

                  username = data['user_name']
                  

                  请记住,现在用户名是一整列,因此 get_user_details(username) 不应期待单个字符串.

                  Keep in mind that now username is a whole column so get_user_details(username) should not be expecting a single string.

                  这篇关于解析用户名以提取用户位置 Twitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:从 Twitter 抓取用户位置 下一篇:如何将 Python 连接到 Db2

                  相关文章

                  最新文章

                    <tfoot id='QTK4O'></tfoot>

                  1. <small id='QTK4O'></small><noframes id='QTK4O'>

                      <bdo id='QTK4O'></bdo><ul id='QTK4O'></ul>
                    1. <legend id='QTK4O'><style id='QTK4O'><dir id='QTK4O'><q id='QTK4O'></q></dir></style></legend>

                    2. <i id='QTK4O'><tr id='QTK4O'><dt id='QTK4O'><q id='QTK4O'><span id='QTK4O'><b id='QTK4O'><form id='QTK4O'><ins id='QTK4O'></ins><ul id='QTK4O'></ul><sub id='QTK4O'></sub></form><legend id='QTK4O'></legend><bdo id='QTK4O'><pre id='QTK4O'><center id='QTK4O'></center></pre></bdo></b><th id='QTK4O'></th></span></q></dt></tr></i><div id='QTK4O'><tfoot id='QTK4O'></tfoot><dl id='QTK4O'><fieldset id='QTK4O'></fieldset></dl></div>