In [2]:
%load_ext cypher
%matplotlib inline
import pandas as pd


/home/davebshow/.virtualenvs/scientific3/lib/python3.4/site-packages/IPython/config.py:13: ShimWarning: The `IPython.config` package has been deprecated. You should import from traitlets.config instead.
  "You should import from traitlets.config instead.", ShimWarning)
/home/davebshow/.virtualenvs/scientific3/lib/python3.4/site-packages/IPython/utils/traitlets.py:5: UserWarning: IPython.utils.traitlets has moved to a top-level traitlets package.
  warn("IPython.utils.traitlets has moved to a top-level traitlets package.")

Number of Tweets


In [2]:
%cypher match (n:tweet) return count(n)


1 rows affected.
Out[2]:
count(n)
608049

Number of users


In [3]:
%cypher match (u:user) return count(u)


1 rows affected.
Out[3]:
count(u)
293584

Top Tweets


In [4]:
%%cypher
match (n:tweet)-[r]-()
with n, count(r) as deg
order by deg desc
limit 10
match (n)<-[:TWEETS]-(u:user)
return u.screen_name as user, n.tid as tid, substring(n.text, 0, 20) as tweet, deg


10 rows affected.
Out[4]:
user tid tweet deg
DXXMIEN 667804078160912384 Le bilan de la prise 3101
SushmaSwaraj 667749009692356609 All 20 Indians rescu 1878
xavieraldekoa 667803133347807232 Hay fotos que valen 1750
Methone 667813005166424064 Geiselnahme in Mali: 1481
Adel__Almalki 667806449477652480 #Photo by #almalki G 1424
MehmetAkifOkur 667745075791847424 Ekranlara bakınca Tü 1278
philstockworld 667757707613614080 Draghi Fever Helps u 1171
AndreaRussett 667679902796247040 I pray that one day 1131
ShujaRabbani 667926175088377856 Must see this! :-) # 1108
Christ_Morray 667686371449044992 Doit on sérieusement 1084

Top Users


In [5]:
%%cypher
match (n:user)-[r]-()
return n.screen_name as user, count(r) as deg
order by deg desc
limit 10


10 rows affected.
Out[5]:
user deg
Reuters 4424
justJasemine 3417
AFP 3370
CNN 3303
wespermee 3301
AP 3196
cnnbrk 3187
iiChattermeii 3165
DXXMIEN 3100
BBCBreaking 2785

Top Tags


In [6]:
%%cypher
match (n:hashtag)-[r]-()
return n.hashtag as hashtags, count(r) as deg
order by deg desc
limit 10


10 rows affected.
Out[6]:
hashtags deg
mali 145905
bamako 24944
maliattacks 12852
isis 7749
news 7216
paris 6722
prayformali 6462
aldubsumptuouslunch 6099
radisson 5825
mtvstars 4178

Language data


In [7]:
langs = %cypher match (n:tweet) where n.lang is not null return distinct n.lang, count(*) as num_tweets order by num_tweets desc


49 rows affected.

In [8]:
lang_df = langs.get_dataframe()
lang_df.set_index("n.lang")[:10].plot(kind="bar")


Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdcecbd1cc0>

% of tweets with geotags


In [9]:
%cypher match (n:tweet) return count(n)


1 rows affected.
Out[9]:
count(n)
608049

In [10]:
%cypher match (n:tweet) where n.coordinates is not null return count(n)


1 rows affected.
Out[10]:
count(n)
6954

In [12]:
6954 / 608049.0  # 1.1%


Out[12]:
0.011436578302077628

Tweets by country


In [13]:
countries = %cypher match (n:tweet) where n.coordinates is not null return distinct n.country, count(*) as num_tweets order by num_tweets desc


138 rows affected.

In [14]:
countries_df = countries.get_dataframe()

In [15]:
countries_df.set_index("n.country")[:20].plot(kind="bar")


Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fdcec817d68>

Average sentiment in English


In [16]:
%cypher match (n:tweet) where n.lang = "en" return avg(n.polarity) as average_en_polarity


1 rows affected.
Out[16]:
average_en_polarity
0.005649926675726534

In [17]:
%cypher match (n:tweet) where n.lang = "en" return avg(n.subjectivity) as average_en_subjectivity


1 rows affected.
Out[17]:
average_en_subjectivity
0.23714375054279724

Average sentiment in French


In [18]:
%cypher match (n:tweet) where n.lang = "fr" return avg(n.polarity) as average_fr_polarity


1 rows affected.
Out[18]:
average_fr_polarity
0.025076915147227433

In [19]:
%cypher match (n:tweet) where n.lang = "fr" return avg(n.subjectivity) as average_fr_subjectivity


1 rows affected.
Out[19]:
average_fr_subjectivity
0.155275638351628

Paris Twitter Stars in Mali dataset

Louis_Tomlinson


In [27]:
%%cypher
match (u:user {uid: '84279963'})
return u.screen_name


1 rows affected.
Out[27]:
u.screen_name
Louis_Tomlinson

In [28]:
%%cypher
match (u:user {uid: '84279963'})-->(n:tweet)
return u.screen_name, n.text


0 rows affected.
Out[28]:
u.screen_name n.text

In [36]:
%%cypher
match (u:user {uid: '84279963'})<--(n:tweet)
return u.screen_name, n.text


1 rows affected.
Out[36]:
u.screen_name n.text
Louis_Tomlinson ı love u ONE DİRECTİON @Harry_Styles @Real_Liam_Payne @Louis_Tomlinson @NiallOfficial and ZAYN MALİK @zaynmalik https://t.co/o3Oeg0HPnk

NiallOfficial


In [29]:
%%cypher
match (u:user {uid: '105119490'})
return u.screen_name


1 rows affected.
Out[29]:
u.screen_name
NiallOfficial

In [32]:
%%cypher
match (u:user {uid: '105119490'})-->(n:tweet)
return u.screen_name, n.text


0 rows affected.
Out[32]:
u.screen_name n.text

In [35]:
%%cypher
match (u:user {uid: '105119490'})<--(n:tweet)
return u.screen_name, n.text


2 rows affected.
Out[35]:
u.screen_name n.text
NiallOfficial @jnlynme @NiallOfficial Mali gud pagka intindi mo. Haha
NiallOfficial ı love u ONE DİRECTİON @Harry_Styles @Real_Liam_Payne @Louis_Tomlinson @NiallOfficial and ZAYN MALİK @zaynmalik https://t.co/o3Oeg0HPnk

RecherchesP


In [33]:
%%cypher
match (u:user {uid: '4185722537'})
return u.screen_name


0 rows affected.
Out[33]:
u.screen_name

Harry_Styles


In [37]:
%%cypher
match (u:user {uid: '181561712'})
return u.screen_name


1 rows affected.
Out[37]:
u.screen_name
Harry_Styles

In [38]:
%%cypher
match (u:user {uid: '181561712'})-->(n:tweet)
return u.screen_name, n.text


0 rows affected.
Out[38]:
u.screen_name n.text

In [39]:
%%cypher
match (u:user {uid: '181561712'})<--(n:tweet)
return u.screen_name, n.text


1 rows affected.
Out[39]:
u.screen_name n.text
Harry_Styles ı love u ONE DİRECTİON @Harry_Styles @Real_Liam_Payne @Louis_Tomlinson @NiallOfficial and ZAYN MALİK @zaynmalik https://t.co/o3Oeg0HPnk

infos140


In [40]:
%%cypher
match (u:user {uid: '1356382759'})
return u.screen_name


1 rows affected.
Out[40]:
u.screen_name
infos140

In [41]:
%%cypher
match (u:user {uid: '1356382759'})-->(n:tweet)
return u.screen_name, n.text


27 rows affected.
Out[41]:
u.screen_name n.text
infos140 🔴 URGENT MALI Pour rappel, le mouvement dirigé par Moktar Belmoktar, al-Mourabitoune, avait déjà revendiqué l’attaque de l’hôtel Radisson
infos140 🔴 ALERTE MALI Dans un communiqué à RFI et AFP à Bamako, le Front de libération du Macina revendique l’attaque qui a fait 22 morts vendredi
infos140 🔴URGENT MALI-BELGIQUE Bruxelles annonce la mort d'un 2eme ressortissant belge hier lors de l'attaque de Bamako
infos140 🔴URGENT MALI Au moins 3 suspects activement recherchés après l’attaque de l’hôtel Radisson hier à Bamako
infos140 🔴 MALI RAPPEL Lundi, les autorités authentifiaient un enregistrement sonore dans lequel le chef d’Ansar Dine appelait à frapper les Français
infos140 🔴URGENT MALI Le bilan provisoire de la prise d'otages à Bamako s’élève à a3 terroristes tués et 27 morts parmi les clients et employés
infos140 🔴 MALI RAPPEL Cet appel du chef (Touareg) d’Ansar Dine à frapper les Français avait été enregistré avant les attentats à Paris de vendredi
infos140 🔴URGENT MALI Selon source locale, les assaillants ont pénétré dans l'enceinte de l'hôtel à bord d'une voiture avec une plaque diplomatique
infos140 🔴 ALERTE MALI Des tirs et des explosions signalés à l’hôtel Radison de Bamako, essentiellement fréquenté par des étrangers.
infos140 🔴ALERTE MALI Des responsables de la Sécurité malienne font état d’un bilan d'au moins 22 morts
infos140 🔴 URGENT MALI Des sources locales parlent de 10 hommes armés (2 selon la direction de l’hôtel). 9 victimes dont des étrangers sont évoquées
infos140 🔴ALERTE MALI Assaut donné à Bamako. Au moins 3 otages tués (AFP)
infos140 🔴URGENT MALI Selon @Reuters, parmi les personnes libérées figurent notamment des otages capables de réciter des versets du Coran
infos140 🔴ALERTE MALI Selon les forces militaires maliennes, la prise d’otages à l’hôtel Radisson de Bamako est terminée
infos140 🔴ALERTE MALI Selon les forces militaires nmaliennes, la prise d’otages à l’hôtel Radisson de Bamako est terminée
infos140 🔴URGENT MALI Une source de sécurité précise à @RTLFrance que l’armée française est sur place. Attaque jihadiste au 7e étage de l’hôtel
infos140 🔴URGENT MALI 80 otages auraient été libérés de l'hôtel Radisson à Bamako selon la TV publique malienne https://t.co/YEikf09Q1q
infos140 🔴ALERTE FRANCE-MALI Le personnel @airfrance (12 personnes) exfiltré et hors de danger (via @leJDD) https://t.co/xoX3oMt1py
infos140 🔴 ALERTE MALI Il y a 170 otages retenus par 2 assaillants (direction hôtel Radison/AFP)
infos140 🔴URGENT FRANCE-MALI Le ministère de l'intérieur annonce l'envoi d'une unité du GIGN à Bamako
infos140 🔴FRANCE-MALI @fhollande appelle ressortissants français à l'étranger 'à prendre toutes les précautions' pour leur sécurité (@erichacquemand)
infos140 🔴ALERTE MALI Le ministre de la sécurité malien indique que les assaillants ne détiennent plus d'otages
infos140 🔴 ALERTE MALI Le groupe Al-Mourabitoun de Mokhtar Belmokhtar (affilié à Al Qaeda) revendique la prise d’otage à Bamako (@FRANCE24)
infos140 🔴 ALERTE MALI Fusillade en cours dans l’hôtel Radisson à Bamako (AFP)
infos140 🔴URGENT MALI Selon le groupe Radisson, 125 clients et 13 employés sont toujours dans l'hôtel de Bamako (Photo @AP) https://t.co/LN9pksxjCv
infos140 🔴ALERTE MALI Le ressortissant belge tué était 1er conseiller de direction de l'administration du parlement Fédération de Wallonie-Bruxelles
infos140 🔴URGENT MALI 18 corps auraient été retrouvés (source de sécurité étrangère) dont celui d’un ressortissant belge (AFP)

justinbieber


In [42]:
%%cypher
match (u:user {uid: '27260086'})
return u.screen_name


1 rows affected.
Out[42]:
u.screen_name
justinbieber

In [45]:
%%cypher
match (u:user {uid: '27260086'})-->(n:tweet)
return u.screen_name, n.text


0 rows affected.
Out[45]:
u.screen_name n.text

In [46]:
%%cypher
match (u:user {uid: '27260086'})<--(n:tweet)
return u.screen_name, n.text


3 rows affected.
Out[46]:
u.screen_name n.text
justinbieber justin yawrum follow me glw i love you bbegim follow me ebesini siktigimin mali @justinbieber #BieberOnAMAs
justinbieber @justinbieber .SENİ ÜZENLERE KARŞI BİR SEVGİMİ BESLİYORSUN PEZEVENK..BURDA SENİN İÇİN ÖLEBİLİCEK BİR SÜRÜ BELIEBER VARKEN NEDEN SELENA MALI?
justinbieber @ilovejanelaa @justinbieber puta! Lagi na lang ganto! Kapag successful ka nanjan sya! Pag-may nagawa kang mali. WALA NANAMAN SYA SA TABI MO!

nytimes


In [47]:
%%cypher
match (u:user {uid: '807095'})
return u.screen_name


1 rows affected.
Out[47]:
u.screen_name
nytimes

In [48]:
%%cypher
match (u:user {uid: '807095'})-->(n:tweet)
return u.screen_name, n.text


16 rows affected.
Out[48]:
u.screen_name n.text
nytimes In the days after an attack in Mali, life goes on with little evidence of increased security https://t.co/J652a7xD2E https://t.co/ZfrrURlxWk
nytimes Your Weekend Briefing: Mali, Brussels, Chicago https://t.co/uDKXe74ygg
nytimes RT @nytimesworld: Paris and Mali attacks expose lethal Al Qaeda-ISIS rivalry. https://t.co/JFRjEUb1qE
nytimes What we know and don’t know about the terrorist attack in Mali https://t.co/ekkefn4NSC https://t.co/igElExNwKz
nytimes 3 Chinese Executives Killed in Mali Attack, Company Says https://t.co/ovTb04M3aT
nytimes France has a long history in Mali, where Islamic rebels have fought a three-year insurgency https://t.co/oh9vvJR4rZ https://t.co/sjS5BWefyS
nytimes Gunmen arrived at Mali hotel in 'a vehicle with diplomatic plates,' pastry chef at hotel said https://t.co/uBqFytc33K
nytimes Breaking News: Gunmen have seized hostages at a Radisson Hotel in Mali https://t.co/DfotnG9FOm
nytimes At least 3 people are dead after gunmen stormed a hotel in Mali and seized 170 hostages https://t.co/G7Vi101qvM
nytimes Officials say the gunmen at the Mali hotel are no longer holding any hostages https://t.co/QHzi5OXWcb https://t.co/DiGDEYtvtd
nytimes Hostages who could do recite Muslim statement were allowed to leave Mali hotel, according to Malian journalist https://t.co/XwsnSsBnxH
nytimes Breaking News: More than 150 hostages have been taken at a Radisson Hotel in Bamako, Mali
https://t.co/eNHzM4qEDa
nytimes What we know about the attack on a hotel in Mali https://t.co/n5npMDM7xA https://t.co/I3omP7NTFl
nytimes Gunmen stormed a hotel in Mali, seizing 140 guests and 30 employees as hostages, per company that runs hotel https://t.co/k4rNAlAWgF
nytimes The Bamako hotel siege illustrates how Islamic extremists in Mali have changed their tactics in recent years https://t.co/TUAd2bh49r
nytimes What we know about the attack on a hotel in Mali. Follow our live blog for updates: https://t.co/uB2w472eTN https://t.co/Afsjmu5NC3

AP


In [49]:
%%cypher
match (u:user {uid: '51241574'})
return u.screen_name


1 rows affected.
Out[49]:
u.screen_name
AP

In [50]:
%%cypher
match (u:user {uid: '51241574'})-->(n:tweet)
return u.screen_name, n.text


27 rows affected.
Out[50]:
u.screen_name n.text
AP Find breaking news and all the latest on the events in Mali on the AP Mobile App. https://t.co/LjHivHiCS5
AP Northern separatists say Mali hotel attack that killed 19 was a clear attempt to derail fragile peace process: https://t.co/Hg9pgHsxoj
AP Report: 6 Turkish Airlines personnel among Mali hostages: https://t.co/s5hVqDsvAe
AP RAW VIDEO: Mali security tightens after hotel massacre https://t.co/SMDYuafvjC
AP The Latest: Muslims in Italy protest the 'abuse' of Islam by attackers in Paris and Mali: https://t.co/tO05Lc7WHQ
AP The Latest: Attackers arrived on foot and surprised Mali hotel guards at shift change: https://t.co/j9hOCvcJBp
AP Chinese company says three of its executives were killed in Mali hotel attack: https://t.co/Fa9CucEGky
AP BREAKING: Chinese company says 3 Chinese business executives among dead in Mali attack.
AP American killed in Mali hotel attack identified as woman from suburban Maryland: https://t.co/vHUVDskSqF
AP Keep up to date with the latest news from Mali. Get the details now in the AP Mobile app. https://t.co/LjHivHiCS5
AP US State Department confirms one American is among at least 19 people killed in Mali hotel attack: https://t.co/wS0eoMNhke
AP (CORRECTS LINK) Death toll remains murky after Islamic militants attack hotel in Mali's capital: https://t.co/GzdsYxbwUX
AP Death toll remains murky after Islamic militants attack hotel in Mali's capital: https://t.co/jIgmbzfkZZ
AP BREAKING: Turkish state media says 6 Turkish Airlines personnel are among hostages in Mali
AP BREAKING: US Embassy: Shooter at Radisson in Bamako, Mali. Americans should shelter in place.
AP BREAKING: UN officials: 2 jihadis killed, 27 people slain in Mali hotel attack, operations ongoing.
AP Army: 3 confirmed dead in attack on Mali hotel in capital: https://t.co/gJnoacZXh2
AP Islamic extremists armed with guns and grenades storm Radisson Blu hotel in Mali, killing three, officials say: https://t.co/O1JUyXf7UU
AP #AP10Things: Hostages taken after Mali hotel attacked; Netanyahu says U.S. frees man convicted of spying for Israel: https://t.co/AUsZhYFyqx
AP Radisson hotel in Mali attacked: https://t.co/ExGhgUlonT
AP Radisson hotel in Mali attacked; 170 hostages taken: https://t.co/3YLig9dHXS
AP Army: About 20 hostages freed from Mali hotel: https://t.co/P5KCDsHGQp
AP BREAKING: Military official says at least 3 dead following attack on Mali hotel where hostages held
AP BREAKING: Mali army commander says about 20 hostages freed from Bamako hotel seized by gunmen.
AP VIDEO: Footage shows police, soldiers outside Mali hotel that was attacked by gunmen: https://t.co/lgYw73RERH
AP BREAKING: Hotel company says 170 hostages - 140 guests and 30 employees - taken in Radisson Blu attack in Mali.
AP Islamic extremists attack hotel in Mali's capital that was full of foreigners: https://t.co/qeOEHSSrKY https://t.co/iE8FrGiOK0

jean_jullien 1851229334


In [51]:
%%cypher
match (u:user {uid: '1851229334'})
return u.screen_name


0 rows affected.
Out[51]:
u.screen_name

Michael5SOS


In [52]:
%%cypher
match (u:user {uid: '403246803'})
return u.screen_name


1 rows affected.
Out[52]:
u.screen_name
Michael5SOS

In [53]:
%%cypher
match (u:user {uid: '403246803'})-->(n:tweet)
return u.screen_name, n.text


0 rows affected.
Out[53]:
u.screen_name n.text

In [54]:
%%cypher
match (u:user {uid: '403246803'})<--(n:tweet)
return u.screen_name, n.text


1 rows affected.
Out[54]:
u.screen_name n.text
Michael5SOS @modestclifford @Bxtchinghemmo @Luke5SOS @Ashton5SOS @Calum5SOS @Michael5SOS @5SOS Calum looks like Mali koa

taylorswift13


In [56]:
%%cypher
match (u:user {screen_name: 'taylorswift13'})
return u.screen_name, u.uid


1 rows affected.
Out[56]:
u.screen_name u.uid
taylorswift13 17919972

In [57]:
%%cypher
match (u:user {uid: '17919972'})-->(n:tweet)
return u.screen_name, n.text


0 rows affected.
Out[57]:
u.screen_name n.text

In [3]:
%%cypher
match (u:user {uid: '17919972'})<--(n:tweet)<--(u2:user)
return u.screen_name, n.text, u2.screen_name


2 rows affected.
Out[3]:
u.screen_name n.text u2.screen_name
taylorswift13 @taylorswift13 what about #Nigeria #Palestine and #Mali or is #Africa &amp; #MiddleEast not included in your opinion? Or what is your view? WillieLynchiDea
taylorswift13 @taylorswift13 @SwiftQuotesPage @21stCenturyGM @DEVINESTJOHN1 @StJohnsTelegram @KatyPerrysBeau1 @St @TheDivineJohn R @lairdofcamster #Mali SultanArabian

In [ ]: