Gaaaon
PR.ready_
Twitterの位置情報を取得し地理別傾向を分析する【ジオタグ分析】
Data

Twitterの位置情報を取得し地理別傾向を分析する【ジオタグ分析】

Twitter上で「ビール」と呟かれたデータを使い地理データを分析してみます。

SHARE

主なポイント

Twitterの位置情報(ジオタグ)を使い「ビール」投稿の地理別傾向を分析する方法を解説しています。2020年の「ビール」投稿708万件のうちジオタグ付きは1.5%(10.5万件)で、2014年の0.4%から増加傾向にあります。Twitter Search APIで位置情報を取得できます。

前回は昨年Twitter上で「ビール」と呟かれたデータを使い、未来の投稿数を時系列ライブラリのProfetを使って予測する方法をご紹介しました。

未来の口コミ件数はAIで予測できるのか | 広報・PR支援の株式会社ガーオン時系列予測AI「Prophet」を使ってTwitterの口コミ量を予測してみます。広報・PR支援の株式会社ガーオン

今回は同じデータを使い、どの場所でビールと呟かれたのかを分析してみたいと思います。

Twitterのジオデータとは

Twitterには投稿の際に場所を付与することができ、GPSで取得した市区町村名や建物・店名などを選択式で選ぶことができます。

2020年1月から12月の1年間に「ビール」とつぶやかれた投稿は全708万3,574件(リツイートとメーカー投稿を除外)で、その中でジオデータが含まれている投稿は10万5,731件でした。これは全体の1.5%の割合となります。

ジオタグ分析を解説した代表書籍 「Twitterの空間分析」 によると、この出現率は2014年の段階で0.4%であったという記載があります。

このことからジオタグ付きツイートの割合は、以前よりも増えていると考えられます。

この地理データはTwitter Search APIなどで取得することができます。

位置情報の区分

位置情報の粒度はtweet_place_typesに入っており、以下の5種類に分かれています。

country[[[122.904034, 24.013343], [122.904034, 45.562897], [153.997697, 45.562897], [153.997697, 24.013343]]]
admin都道府県[[[138.942847, 24.224701], [138.942847, 35.89849], [153.986676, 35.89849], [153.986676, 24.224701]]]
city市区町村[[[139.673228, 35.673404], [139.673228, 35.72991], [139.745133, 35.72991], [139.745133, 35.673404]]]
neighborhood場所(川や浜など)[[[173.062638, -41.246544], [173.062638, -41.207572], [173.10031, -41.207572], [173.10031, -41.246544]]]
poi店舗や特定の場所など[[[139.880391, 35.632922], [139.880391, 35.632922], [139.880391, 35.632922], [139.880391, 35.632922]]]
※poiの場合だけ4つの座標が全て同じになる

例えば作家の藤沢数希さんは2020年に7回ビールとつぶやいており、下記2月1日にはマカオから投稿していることが分かります。

Twitter Embed

Xでこのポストを表示する

Kazuki Fujisawa

@kazu_fujisawa

·

フォローする

Xで表示

ガラガラのマカオでエッフェル塔を見ながら青島ビール飲んでフレンチ食べてます。

画像

画像

画像

午前10:49 · 2020年2月1日

X広告の情報とプライバシー

41 返信

ポストへのリンクをコピー

3件の返信を読む

この投稿をSerch APIで取得すると、下記の情報が得られます。

{'created_at': 'Sat Feb 01 10:49:58 +0000 2020',
  'id': 1223559106859950082,
  'id_str': '1223559106859950082',
  'text': 'ガラガラのマカオでエッフェル塔を見ながら青島ビール飲んでフレンチ食べてます。 https://t.co/CDmelkEmaj',
  'display_text_range': [0, 38],
  'source': '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a>',
  'truncated': False,
  'in_reply_to_status_id': None,
  'in_reply_to_status_id_str': None,
  'in_reply_to_user_id': None,
  'in_reply_to_user_id_str': None,
  'in_reply_to_screen_name': None,
  'user': {'id': 103281527,
   'id_str': '103281527',
   'name': 'Kazuki Fujisawa',
   'screen_name': 'kazu_fujisawa',
   'location': 'Hong Kong',
   'url': 'http://blog.livedoor.jp/kazu_fujisawa/',
   'description': '藤沢数希。PhD。メルマガ週刊金融日記。物理学研究者、投資銀行クオンツ・トレーダー職を経て、作家・投資家。香港在住。著書:なぜ投資のプロはサルに負けるのか、日本人がグローバル資本主義を生き抜くための経済学入門、反原発の不都合な真実、外資系金融の終わり、損する結婚 儲かる離婚、ぼくは愛を証明しようと思う。',
   'translator_type': 'none',
   'derived': {'locations': [{'country': 'Hong Kong',\
      'country_code': 'HK',\
      'locality': 'Hong Kong Special Administrative Region',\
      'full_name': 'Hong Kong Special Administrative Region, Hong Kong',\
      'geo': {'coordinates': [114.16667, 22.25], 'type': 'point'}}]},
   'protected': False,
   'verified': True,
   'followers_count': 188240,
   'friends_count': 1149,
   'listed_count': 6283,
   'favourites_count': 471,
   'statuses_count': 55528,
   'created_at': 'Sat Jan 09 14:23:59 +0000 2010',
   'utc_offset': None,
   'time_zone': None,
   'geo_enabled': True,
   'lang': None,
   'contributors_enabled': False,
   'is_translator': False,
   'profile_background_color': '131516',
   'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme14/bg.gif',
   'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme14/bg.gif',
   'profile_background_tile': True,
   'profile_link_color': '646B7A',
   'profile_sidebar_border_color': 'EEEEEE',
   'profile_sidebar_fill_color': 'EFEFEF',
   'profile_text_color': '333333',
   'profile_use_background_image': True,
   'profile_image_url': 'http://pbs.twimg.com/profile_images/669366272/KinyuuNikkiWadokaichin_normal.jpg',
   'profile_image_url_https': 'https://pbs.twimg.com/profile_images/669366272/KinyuuNikkiWadokaichin_normal.jpg',
   'profile_banner_url': 'https://pbs.twimg.com/profile_banners/103281527/1575684032',
   'default_profile': False,
   'default_profile_image': False,
   'following': None,
   'follow_request_sent': None,
   'notifications': None,
   'withheld_in_countries': []},
  'geo': None,
  'coordinates': None,
  'place': {'id': '0fc33aa2d1946000',
   'url': 'https://api.twitter.com/1.1/geo/id/0fc33aa2d1946000.json',
   'place_type': 'poi',
   'name': 'Eiffel Tower',
   'full_name': 'Eiffel Tower',
   'country_code': 'MO',
   'country': 'Macau',
   'bounding_box': {'type': 'Polygon',
    'coordinates': [[[113.561974, 22.144049],\
      [113.561974, 22.144049],\
      [113.561974, 22.144049],\
      [113.561974, 22.144049]]]},
   'attributes': {}},
  'contributors': None,
  'is_quote_status': False,
  'quote_count': 1,
  'reply_count': 3,
  'retweet_count': 4,
  'favorite_count': 45,
  'entities': {'hashtags': [],
   'urls': [],
   'user_mentions': [],
   'symbols': [],
   'media': [{'id': 1223559091676532736,\
     'id_str': '1223559091676532736',\
     'indices': [39, 62],\
     'media_url': 'http://pbs.twimg.com/media/EPr0gt0UUAA_3yG.jpg',\
     'media_url_https': 'https://pbs.twimg.com/media/EPr0gt0UUAA_3yG.jpg',\
     'url': 'https://t.co/CDmelkEmaj',\
     'display_url': 'pic.twitter.com/CDmelkEmaj',\
     'expanded_url': 'https://twitter.com/kazu_fujisawa/status/1223559106859950082/photo/1',\
     'type': 'photo',\
     'sizes': {'small': {'w': 510, 'h': 680, 'resize': 'fit'},\
      'thumb': {'w': 150, 'h': 150, 'resize': 'crop'},\
      'large': {'w': 1536, 'h': 2048, 'resize': 'fit'},\
      'medium': {'w': 900, 'h': 1200, 'resize': 'fit'}}}]},
  'extended_entities': {'media': [{'id': 1223559091676532736,\
     'id_str': '1223559091676532736',\
     'indices': [39, 62],\
     'media_url': 'http://pbs.twimg.com/media/EPr0gt0UUAA_3yG.jpg',\
     'media_url_https': 'https://pbs.twimg.com/media/EPr0gt0UUAA_3yG.jpg',\
     'url': 'https://t.co/CDmelkEmaj',\
     'display_url': 'pic.twitter.com/CDmelkEmaj',\
     'expanded_url': 'https://twitter.com/kazu_fujisawa/status/1223559106859950082/photo/1',\
     'type': 'photo',\
     'sizes': {'small': {'w': 510, 'h': 680, 'resize': 'fit'},\
      'thumb': {'w': 150, 'h': 150, 'resize': 'crop'},\
      'large': {'w': 1536, 'h': 2048, 'resize': 'fit'},\
      'medium': {'w': 900, 'h': 1200, 'resize': 'fit'}}},\
    {'id': 1223559091680710656,\
     'id_str': '1223559091680710656',\
     'indices': [39, 62],\
     'media_url': 'http://pbs.twimg.com/media/EPr0gt1UEAAvjYJ.jpg',\
     'media_url_https': 'https://pbs.twimg.com/media/EPr0gt1UEAAvjYJ.jpg',\
     'url': 'https://t.co/CDmelkEmaj',\
     'display_url': 'pic.twitter.com/CDmelkEmaj',\
     'expanded_url': 'https://twitter.com/kazu_fujisawa/status/1223559106859950082/photo/1',\
     'type': 'photo',\
     'sizes': {'small': {'w': 495, 'h': 680, 'resize': 'fit'},\
      'thumb': {'w': 150, 'h': 150, 'resize': 'crop'},\
      'large': {'w': 1492, 'h': 2048, 'resize': 'fit'},\
      'medium': {'w': 874, 'h': 1200, 'resize': 'fit'}}},\
    {'id': 1223559091756228609,\
     'id_str': '1223559091756228609',\
     'indices': [39, 62],\
     'media_url': 'http://pbs.twimg.com/media/EPr0guHUYAEDqrN.jpg',\
     'media_url_https': 'https://pbs.twimg.com/media/EPr0guHUYAEDqrN.jpg',\
     'url': 'https://t.co/CDmelkEmaj',\
     'display_url': 'pic.twitter.com/CDmelkEmaj',\
     'expanded_url': 'https://twitter.com/kazu_fujisawa/status/1223559106859950082/photo/1',\
     'type': 'photo',\
     'sizes': {'thumb': {'w': 150, 'h': 150, 'resize': 'crop'},\
      'medium': {'w': 1200, 'h': 900, 'resize': 'fit'},\
      'small': {'w': 680, 'h': 510, 'resize': 'fit'},\
      'large': {'w': 2048, 'h': 1536, 'resize': 'fit'}}}]},
  'favorited': False,
  'retweeted': False,
  'possibly_sensitive': False,
  'filter_level': 'low',
  'lang': 'ja',
  'matching_rules': [{'tag': None}]}

placeという箇所に地理データが記載されています。

'place': {'id': '0fc33aa2d1946000',
   'url': 'https://api.twitter.com/1.1/geo/id/0fc33aa2d1946000.json',
   'place_type': 'poi',
   'name': 'Eiffel Tower',
   'full_name': 'Eiffel Tower',
   'country_code': 'MO',
   'country': 'Macau',
   'bounding_box': {'type': 'Polygon',
    'coordinates': [[[113.561974, 22.144049],\
      [113.561974, 22.144049],\
      [113.561974, 22.144049],\
      [113.561974, 22.144049]]]},

このツイートに含まれている位置データは

place_typeが

'place_type': 'poi', 'name': 'Eiffel Tower',

となり、緯度経度が

[[[113.561974, 22.144049],

[113.561974, 22.144049],

[113.561974, 22.144049],

[113.561974, 22.144049]]]

となります。

typeがpoiなので一番粒度の細かいデータであり、全ての緯度経度が同一となっておりことが分かります。

マップでこの場所を見ると

確かにマカオにエッフェル塔がありました。

全10万件超のデータを地図上にプロット

2020年に位置情報が付けられビールと投稿された10万5,731件を地図上にプロットすると下記のようになりました。

place_typeがpoli以外の場合は4つの座標が異なりますが、今回は左上の座標を基準にプロットしており、サイズをFollower/Follow比に設定しています。

こうしてみると意外と海外から投稿されていることなどが分かります。

Twitterの位置情報の解説は下記書籍くらいしか代表的なものがなく、ネットにもあまり活用方法が載っていないため利用するのが難しそうですが、特定のブランドがどの場所で呟かれているのかを調べたり、観光やインバウンドなどの行動データとして分析してみると面白いかもしれません。

以上、Twitterの位置情報を可視化する方法の解説でした。

※当社ではTwitterやInstagramなどのデータ抽出や、データスクレイピングの代行も行っています。ご依頼の際は、 お問い合せフォーム よりお気軽にお問い合せください。

SHARE
Twitterの位置情報を取得し地理別傾向を分析する【ジオタグ分析】 | 株式会社ガーオン