惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
小众软件
小众软件
I
InfoQ
有赞技术团队
有赞技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Martin Fowler
Martin Fowler
月光博客
月光博客
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
V
Visual Studio Blog
博客园 - 叶小钗
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
GbyAI
GbyAI
P
Proofpoint News Feed
Apple Machine Learning Research
Apple Machine Learning Research

qubeijun的博客

言语理解与表达 父亲往事-我儿子叫冬冬 公务员行测答题顺序及用时及答题技巧 判断推理 数量关系 冬甜夫妇5-10-5-21日本蜜月行程安排回归总结篇(无图片) 冬甜夫妇5.10-5.21日本蜜月行程安排计划篇 5.1 小贝壳疫苗计划 100DAYS 父亲往事-猴牤大爷的“帽子” 父亲往事-姨妈家的葡萄架 父亲往事-十五的月饼 父亲往事-姑妈的压岁钱 父亲往事-母亲的缝纫机父亲的锯 父亲往事-家属来队 父亲往事-新兵连的生活 父亲往事-村北的槐树林 父亲往事-小贝壳 公务员面试 系统架构设计师 图形推理 数学运算 父亲往事-惊蛰 资料分析 父亲往事-偷吃西红柿有绝窍 父亲往事-毯子衣服 父亲往事-水壶煮鸡蛋 父亲往事-煎饼蘸香油 系统架构设计师论文
python3循环读取excel文件并写入json
qubeijun · 2018-08-03 · via qubeijun的博客

发表于|更新于|python

|总字数:278|阅读时长:1分钟|浏览量:|

文件内容:

excel内容:

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import xlrd
import json
import operator


def read_xlsx(filename):
# 打开excel文件
data1 = xlrd.open_workbook(filename)
# 读取第一个工作表
table = data1.sheets()[0]
# 统计行数
n_rows = table.nrows

data = []

# 微信文章属性:wechat_name wechat_id title abstract url time read like number
for v in range(1, n_rows-1):
# 每一行数据形成一个列表
values = table.row_values(v)
# 列表形成字典
data.append({'wechat_name': values[0],
'wechat_id': values[1],
'title': values[2],
'abstract': values[3],
'url': values[4],
'time': values[5],
'read': values[6],
'like': values[7],
'number': values[8],
})
# 返回所有数据
return data


if __name__ == '__main__':
d = []
# 循环打开每个excel
for i in range(1, 16):
d1 = read_xlsx('./excel data/'+str(i)+'.xlsx')
d.extend(d1)

# 微信文章属性
# 按时间升序排列
d = sorted(d, key=operator.itemgetter('time'))
# 写入json文件
with open('article.json', 'w', encoding='utf-8') as f:
f.write(json.dumps(d, ensure_ascii=False, indent=2))

name = []
# 微信id写文件
f1 = open('wechat_id.txt', 'w')
for i in d:
if i['wechat_id'] not in name:
name.append(i['wechat_id'])
f1.writelines(i['wechat_id'])
f1.writelines('\n')

print(len(name))

结果:

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 qubeijun的博客

赞助

  • 微信

    微信

  • 支付宝

    支付宝