Skip to content

Instantly share code, notes, and snippets.

@ajitesh123
Created May 27, 2019 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajitesh123/2605ff995a5848d57cb46eebb2546c82 to your computer and use it in GitHub Desktop.
Save ajitesh123/2605ff995a5848d57cb46eebb2546c82 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 325,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Tweets</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Called on Vice President Shri @MVenkaiahNaidu ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Thank you President @jairbolsonaro. I look for...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>शुभकामनाओं के लिए बहुत-बहुत आभार @aanandlrai ज...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Thank you @SDhawan25. We will continue to serv...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Thank you @mauriciomacri! I look forward to co...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Thanks. @varunsharma90 https://t.co/sFoBIw1AJm</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Thank you for the good wishes. @Its_Badshah. h...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>For 70 years, India’s poor were betrayed. In t...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Our Constitution is a rich and extensive socia...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>I thank colleagues of the BJP and NDA for plac...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Tweets\n",
"0 Called on Vice President Shri @MVenkaiahNaidu ...\n",
"1 Thank you President @jairbolsonaro. I look for...\n",
"2 शुभकामनाओं के लिए बहुत-बहुत आभार @aanandlrai ज...\n",
"3 Thank you @SDhawan25. We will continue to serv...\n",
"4 Thank you @mauriciomacri! I look forward to co...\n",
"5 Thanks. @varunsharma90 https://t.co/sFoBIw1AJm\n",
"6 Thank you for the good wishes. @Its_Badshah. h...\n",
"7 For 70 years, India’s poor were betrayed. In t...\n",
"8 Our Constitution is a rich and extensive socia...\n",
"9 I thank colleagues of the BJP and NDA for plac..."
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"data=pd.DataFrame(data=[tweet.text for tweet in tweets], columns=['Tweets'])\n",
"display(data.head(10))"
]
},
{
"cell_type": "code",
"execution_count": 326,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_api', '_json', 'author', 'contributors', 'coordinates', 'created_at', 'destroy', 'entities', 'extended_entities', 'favorite', 'favorite_count', 'favorited', 'geo', 'id', 'id_str', 'in_reply_to_screen_name', 'in_reply_to_status_id', 'in_reply_to_status_id_str', 'in_reply_to_user_id', 'in_reply_to_user_id_str', 'is_quote_status', 'lang', 'parse', 'parse_list', 'place', 'possibly_sensitive', 'retweet', 'retweet_count', 'retweeted', 'retweets', 'source', 'source_url', 'text', 'truncated', 'user']\n"
]
}
],
"source": [
"print(dir(tweets[0]))"
]
},
{
"cell_type": "code",
"execution_count": 327,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Tweets</th>\n",
" <th>Length</th>\n",
" <th>ID</th>\n",
" <th>Date</th>\n",
" <th>Source</th>\n",
" <th>Likes</th>\n",
" <th>RTs</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Called on Vice President Shri @MVenkaiahNaidu ...</td>\n",
" <td>88</td>\n",
" <td>1132527835812225024</td>\n",
" <td>2019-05-26 06:04:12</td>\n",
" <td>Twitter Web Client</td>\n",
" <td>7845</td>\n",
" <td>1027</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Thank you President @jairbolsonaro. I look for...</td>\n",
" <td>140</td>\n",
" <td>1132341572090191872</td>\n",
" <td>2019-05-25 17:44:03</td>\n",
" <td>Twitter for iPhone</td>\n",
" <td>18518</td>\n",
" <td>2573</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>शुभकामनाओं के लिए बहुत-बहुत आभार @aanandlrai ज...</td>\n",
" <td>72</td>\n",
" <td>1132340882898915329</td>\n",
" <td>2019-05-25 17:41:19</td>\n",
" <td>Twitter for iPhone</td>\n",
" <td>14741</td>\n",
" <td>1529</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Thank you @SDhawan25. We will continue to serv...</td>\n",
" <td>123</td>\n",
" <td>1132340602132209664</td>\n",
" <td>2019-05-25 17:40:12</td>\n",
" <td>Twitter for iPhone</td>\n",
" <td>21601</td>\n",
" <td>2048</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Thank you @mauriciomacri! I look forward to co...</td>\n",
" <td>140</td>\n",
" <td>1132340296866500608</td>\n",
" <td>2019-05-25 17:38:59</td>\n",
" <td>Twitter for iPhone</td>\n",
" <td>11312</td>\n",
" <td>1469</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Thanks. @varunsharma90 https://t.co/sFoBIw1AJm</td>\n",
" <td>46</td>\n",
" <td>1132339567489617920</td>\n",
" <td>2019-05-25 17:36:05</td>\n",
" <td>Twitter for iPhone</td>\n",
" <td>8538</td>\n",
" <td>968</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Thank you for the good wishes. @Its_Badshah. h...</td>\n",
" <td>68</td>\n",
" <td>1132339386450939907</td>\n",
" <td>2019-05-25 17:35:22</td>\n",
" <td>Twitter for iPhone</td>\n",
" <td>11659</td>\n",
" <td>1204</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>For 70 years, India’s poor were betrayed. In t...</td>\n",
" <td>140</td>\n",
" <td>1132320901003747328</td>\n",
" <td>2019-05-25 16:21:54</td>\n",
" <td>Twitter Media Studio</td>\n",
" <td>34046</td>\n",
" <td>6666</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Our Constitution is a rich and extensive socia...</td>\n",
" <td>139</td>\n",
" <td>1132318267832295424</td>\n",
" <td>2019-05-25 16:11:27</td>\n",
" <td>Twitter Web Client</td>\n",
" <td>64312</td>\n",
" <td>9790</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>I thank colleagues of the BJP and NDA for plac...</td>\n",
" <td>139</td>\n",
" <td>1132314619161206785</td>\n",
" <td>2019-05-25 15:56:57</td>\n",
" <td>Twitter Web Client</td>\n",
" <td>30804</td>\n",
" <td>4793</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Tweets Length \\\n",
"0 Called on Vice President Shri @MVenkaiahNaidu ... 88 \n",
"1 Thank you President @jairbolsonaro. I look for... 140 \n",
"2 शुभकामनाओं के लिए बहुत-बहुत आभार @aanandlrai ज... 72 \n",
"3 Thank you @SDhawan25. We will continue to serv... 123 \n",
"4 Thank you @mauriciomacri! I look forward to co... 140 \n",
"5 Thanks. @varunsharma90 https://t.co/sFoBIw1AJm 46 \n",
"6 Thank you for the good wishes. @Its_Badshah. h... 68 \n",
"7 For 70 years, India’s poor were betrayed. In t... 140 \n",
"8 Our Constitution is a rich and extensive socia... 139 \n",
"9 I thank colleagues of the BJP and NDA for plac... 139 \n",
"\n",
" ID Date Source Likes RTs \n",
"0 1132527835812225024 2019-05-26 06:04:12 Twitter Web Client 7845 1027 \n",
"1 1132341572090191872 2019-05-25 17:44:03 Twitter for iPhone 18518 2573 \n",
"2 1132340882898915329 2019-05-25 17:41:19 Twitter for iPhone 14741 1529 \n",
"3 1132340602132209664 2019-05-25 17:40:12 Twitter for iPhone 21601 2048 \n",
"4 1132340296866500608 2019-05-25 17:38:59 Twitter for iPhone 11312 1469 \n",
"5 1132339567489617920 2019-05-25 17:36:05 Twitter for iPhone 8538 968 \n",
"6 1132339386450939907 2019-05-25 17:35:22 Twitter for iPhone 11659 1204 \n",
"7 1132320901003747328 2019-05-25 16:21:54 Twitter Media Studio 34046 6666 \n",
"8 1132318267832295424 2019-05-25 16:11:27 Twitter Web Client 64312 9790 \n",
"9 1132314619161206785 2019-05-25 15:56:57 Twitter Web Client 30804 4793 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#Add relevant data to Panda DataFrame \n",
"data['Length']=np.array([len(tweet.text) for tweet in tweets])\n",
"data['ID']=np.array([tweet.id for tweet in tweets])\n",
"data['Date']=np.array([tweet.created_at for tweet in tweets])\n",
"data['Source']=np.array([tweet.source for tweet in tweets])\n",
"data['Likes']=np.array([tweet.favorite_count for tweet in tweets])\n",
"data['RTs']=np.array([tweet.retweet_count for tweet in tweets])\n",
"display(data.head(10))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment