import pandas as pd
from datetime import datetime fn = r"D:\OneDrive - UNSW\tweets_flu.csv"
df = pd.read_csv(fn)
for i in range(len(df)):
t = df.iloc[i]['created_at']
w = datetime.strptime(t, "%Y-%m-%d %H:%M:%S").strftime("%W")
ws.append(w) ws = []
df['ws'] = ws
df['ws'].value_counts()

 

import pandas as pd
from datetime import datetime fn = r"D:\OneDrive - UNSW\tweets_flu.csv"
df = pd.read_csv(fn)
for i in range(len(df)):
t = df.iloc[i]['created_at']
w = datetime.strptime(t, "%Y-%m-%d %H:%M:%S").strftime("%W")
ws.append(w) ws = []
df['ws'] = ws
df['ws'].value_counts() wss = [] for i in a.index:
wss.append((i, a[i])) sorted(wss, key=lambda x:x[0])
[('12', 56), ('13', 22), ('14', 41), ('15', 52), ('16', 25), ('17', 45), ('18', 63), ('19', 54), ('20', 51), ('21', 143), ('22', 77), ('23', 53), ('24', 133), ('25', 93), ('26', 77), ('27', 125), ('28', 63), ('29', 67), ('30', 56), ('31', 67), ('32', 62), ('33', 67), ('34', 54), ('35', 41), ('36', 43), ('37', 24), ('38', 29), ('39', 33), ('40', 14)]

save data in csv file.

fn = r"D:\OneDrive - UNSW\01-UNSW\02-Papers\20190514-Prediction Location of Twitter\Data\Paper\weekly_tweets.csv"

fo = open(fn, "w+")
for e in a:
fo.write(e[0] + ", " + str(e[1]) + "\n")
>>> import re
>>> def word_extraction(sentence):
ignore = ['a', "the", "is"]
words = re.sub("[^\w]", " ", sentence).split()
cleaned_text = [w.lower() for w in words if w not in ignore]
return cleaned_text >>> a = "alex is. good guy."
>>> word_extraction(a)
['alex', 'good', 'guy']
>>> a = ["fluence", 'good']
>>> b = 'flu'
>>> b in a
False
>>> 'go' in a
False
>>> 'good' in a
True
>>> import nltk
>>> nltk.download('stopwords')
[nltk_data] Downloading package stopwords to
[nltk_data] C:\Users\z5194293\AppData\Roaming\nltk_data...
[nltk_data] Unzipping corpora\stopwords.zip.
True
>>> from nltk.corpus import stopwords
>>> stopwords.words('english')
['i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', "you're", "you've", "you'll", "you'd", 'your', 'yours', 'yourself', 'yourselves', 'he', 'him', 'his', 'himself', 'she', "she's", 'her', 'hers', 'herself', 'it', "it's", 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves', 'what', 'which', 'who', 'whom', 'this', 'that', "that'll", 'these', 'those', 'am', 'is', 'are', 'was', 'were', 'be', 'been', 'being', 'have', 'has', 'had', 'having', 'do', 'does', 'did', 'doing', 'a', 'an', 'the', 'and', 'but', 'if', 'or', 'because', 'as', 'until', 'while', 'of', 'at', 'by', 'for', 'with', 'about', 'against', 'between', 'into', 'through', 'during', 'before', 'after', 'above', 'below', 'to', 'from', 'up', 'down', 'in', 'out', 'on', 'off', 'over', 'under', 'again', 'further', 'then', 'once', 'here', 'there', 'when', 'where', 'why', 'how', 'all', 'any', 'both', 'each', 'few', 'more', 'most', 'other', 'some', 'such', 'no', 'nor', 'not', 'only', 'own', 'same', 'so', 'than', 'too', 'very', 's', 't', 'can', 'will', 'just', 'don', "don't", 'should', "should've", 'now', 'd', 'll', 'm', 'o', 're', 've', 'y', 'ain', 'aren', "aren't", 'couldn', "couldn't", 'didn', "didn't", 'doesn', "doesn't", 'hadn', "hadn't", 'hasn', "hasn't", 'haven', "haven't", 'isn', "isn't", 'ma', 'mightn', "mightn't", 'mustn', "mustn't", 'needn', "needn't", 'shan', "shan't", 'shouldn', "shouldn't", 'wasn', "wasn't", 'weren', "weren't", 'won', "won't", 'wouldn', "wouldn't"]
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> fn = r"D:\Data\CSV\AUS_AVG_tweets_Centroid_Lon_lat.csv"
>>> import pandas as pd
>>> df = pd.read_csv(fn)
>>> df.head()
OBJECTID_1 OBJECTID ... d_y distance
0 1 1 ... 0.009560 1.149847
1 2 2 ... 0.204213 36.363808
2 3 3 ... -0.003238 0.394919
3 4 4 ... 0.000109 1.063002
4 5 5 ... -0.004560 0.549273 [5 rows x 14 columns]
>>> df.columns
Index(['OBJECTID_1', 'OBJECTID', 'SA2_NAME16', 'CENTROID_X', 'CENTROID_Y',
'State', 'Count_', 'Avg_co_lon', 'Avg_co_lat', 'Shape_Length',
'Shape_Area', 'd_x', 'd_y', 'distance'],
dtype='object')
>>> dff = df[['SA2_NAME16']]
>>> dff.head()
SA2_NAME16
0 Albany
1 Albany Region
2 Alexander Heights - Koondoola
3 Alkimos - Eglinton
4 Applecross - Ardross
>>> dff = df[['SA2_NAME16', 'CENTROID_X']]
>>> dff.head()
SA2_NAME16 CENTROID_X
0 Albany 117.899601
1 Albany Region 118.207172
2 Alexander Heights - Koondoola 115.865812
3 Alkimos - Eglinton 115.677976
4 Applecross - Ardross 115.836085
>>> dff = df[['SA2_NAME16', 'CENTROID_X', 'CENTROID_Y', 'State', 'Avg_co_lon', 'Avg_co_lat', 'Shape_Area']]
>>> dff.head()
SA2_NAME16 CENTROID_X ... Avg_co_lat Shape_Area
0 Albany 117.899601 ... -35.017921 0.003012
1 Albany Region 118.207172 ... -34.923186 0.394533
2 Alexander Heights - Koondoola 115.865812 ... -31.831628 0.000638
3 Alkimos - Eglinton 115.677976 ... -31.600350 0.003104
4 Applecross - Ardross 115.836085 ... -32.014606 0.000518 [5 rows x 7 columns]
>>> dff.columns
Index(['SA2_NAME16', 'CENTROID_X', 'CENTROID_Y', 'State', 'Avg_co_lon',
'Avg_co_lat', 'Shape_Area'],
dtype='object')
>>> dff.to_csv(r"D:\Data\CSV\AUS_AVG_tweets_Centroid_Lon_lat_lite.csv", index=False") SyntaxError: EOL while scanning string literal
>>> dff.to_csv(r"D:\Data\CSV\AUS_AVG_tweets_Centroid_Lon_lat_lite.csv", index=False) >>> dff = pd.read_csv(r"D:\Data\CSV\AUS_AVG_tweets_Centroid_Lon_lat_lite.csv") >>> dff.head() NAME CEN_X ... AVG_Y AREA
0 Albany 117.899601 ... -35.017921 0.003012
1 Albany Region 118.207172 ... -34.923186 0.394533
2 Alexander Heights - Koondoola 115.865812 ... -31.831628 0.000638
3 Alkimos - Eglinton 115.677976 ... -31.600350 0.003104
4 Applecross - Ardross 115.836085 ... -32.014606 0.000518 [5 rows x 7 columns]
>>> dff.columns Index(['NAME', 'CEN_X', 'CEN_Y', 'STATE', 'AVG_X', 'AVG_Y', 'AREA'], dtype='object')
>>>

 

【449】backup get weekly tweets的更多相关文章

  1. 【449】Win10 蓝牙耳机链接没有声音

    Exhausting,当电脑出现问题的时候!!! 问题描述:蓝牙耳机连接上了电脑,但是通过右下角声音按钮无法选择蓝牙耳机的选项??? 解决方案:在声音按钮处点击右键,选择最下面的菜单“troubles ...

  2. 【LeetCode】树(共94题)

    [94]Binary Tree Inorder Traversal [95]Unique Binary Search Trees II (2018年11月14日,算法群) 给了一个 n,返回结点是 1 ...

  3. 【BZOJ1150】[CTSC2007]数据备份Backup 双向链表+堆(模拟费用流)

    [BZOJ1150][CTSC2007]数据备份Backup Description 你在一家 IT 公司为大型写字楼或办公楼(offices)的计算机数据做备份.然而数据备份的工作是枯燥乏味的,因此 ...

  4. 【LeetCode】449. Serialize and Deserialize BST 解题报告(Python)

    [LeetCode]449. Serialize and Deserialize BST 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/pro ...

  5. 【BBED】BBED模拟并修复ORA-08102错误

    [BBED]BBED模拟并修复ORA-08102错误 1.1  BLOG文档结构图 1.2  前言部分 1.2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其 ...

  6. python基础学习十 logging模块详细使用【转载】

    很多程序都有记录日志的需求,并且日志中包含的信息既有正常的程序访问日志,还可能有错误.警告等信息输出,python的logging模块提供了标准的日志接口,你可以通过它存储各种格式的日志,主要用于输出 ...

  7. 【TTS】传输表空间AIX asm -> linux asm

    [TTS]传输表空间AIX asm -> linux asm 一.1  BLOG文档结构图       一.2  前言部分   一.2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌 ...

  8. 【TTS】传输表空间Linux asm -> AIX asm

    [TTS]传输表空间Linux asm -> AIX asm 一.1  BLOG文档结构图       一.2  前言部分   一.2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌 ...

  9. Linux学习之路-Linux-at及cron命令【7】---20171215

    Linux学习之路-Linux-at及cron命令[7]---20171215 DannyExia000人评论986人阅读2017-12-24 17:28:03   ntpdate 命令 [root@ ...

随机推荐

  1. Python入门篇-数据结构树(tree)的遍历

    Python入门篇-数据结构树(tree)的遍历 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.遍历 迭代所有元素一遍. 二.树的遍历 对树中所有元素不重复地访问一遍,也称作扫 ...

  2. Kubernetes网络之Flannel工作原理

    目录 1.Docker网络模式 1.1 bridge网络的构建过程 1.2 外部访问 2.Kubernetes网络模式 2.1 同一个Pod中容器之间的通信 2.2 不同Pod中容器之间的通信 2.3 ...

  3. 【MySQL】FIND_IN_SET、LIKE、IN的区别

    现在有张新闻表,里面有新闻名称name字段,有新闻类型type字段,1代表头条,2代表推荐,11代表热点,22代表最新,现在表中有两条记录,存储形式如下,现在的需求是查找头条新闻,及type中包含1的 ...

  4. Spark RDD :Spark API--Spark RDD

    一.RDD的概述 1.1 什么是RDD? RDD(Resilient Distributed Dataset)叫做弹性分布式数据集,是Spark中最基本的数据抽象,它代表一个不可变.可分区.里面的元素 ...

  5. django-缓存django-redis

    https://django-redis-chs.readthedocs.io/zh_CN/latest/ 安装 django-redis 最简单的方法就是用 pip : pip install dj ...

  6. Mybatis框架-update节点元素的使用

    今天我们学习一下mybatis框架中的update节点元素的使用 需求:修改用户表中的一条数据记录,修改编号为21的用户的密码 UserMapper.xml UserMapper.java 编写测试方 ...

  7. 洛谷 P1908 逆序对 题解

    每日一题 day43 打卡 Analysis 因为数据规模,所以我们需要对其进行离散化,新创一个数组a里面来放在我们的初始序列中在这个位置上的数是第几大的这里还要用一个小技巧排序,关于离散化的技巧我们 ...

  8. learning java FileVisitor 遍丽文件及路径

    import java.io.IOException; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttribut ...

  9. learing java NIO 之 ReadFile

    import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import ja ...

  10. 推荐一款分布式微服务框架 Surging

    surging   surging 是一个分布式微服务框架,提供高性能RPC远程服务调用,采用Zookeeper.Consul作为surging服务的注册中心,集成了哈希,随机,轮询,压力最小优先作为 ...