kevinhyc commited on
Commit
eff7191
·
verified ·
1 Parent(s): 5b10c55

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +66 -0
main.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import Dataset
2
+ import json
3
+ from datasets import concatenate_datasets, Dataset
4
+
5
+ arrow_files = ['data/data-00000-of-00003.arrow','data/data-00001-of-00003.arrow','data/data-00002-of-00003.arrow']
6
+ ds = concatenate_datasets([Dataset.from_file(arrow_file) for arrow_file in arrow_files])
7
+
8
+ threshold = 6000
9
+ df = ds.to_pandas()
10
+ df['question_id'] = df['METADATA'].apply(lambda x: int(json.loads(x)['question_id']))
11
+ df = df.drop('SOURCE', axis=1)
12
+ df = df.drop('METADATA', axis=1)
13
+ df = df[df['upvotes'] > threshold]
14
+
15
+ import pandas as pd
16
+ pd.set_option('display.max_columns', None) # Show all columns
17
+ pd.set_option('display.max_rows', None)
18
+ pd.set_option('display.max_colwidth', 200)
19
+
20
+ # Set display options
21
+
22
+ filtered_df = df[df['INSTRUCTION'].str.contains('吃饭')]
23
+
24
+ class1 = ['船','高中历史', '陈情令','流浪地球', '厦门','鞋','购买','高中化学','考研政治','高中政治','英语','数学','语文','解题','高二','高三','演员','周星驰','王宝强','口吻','编程','免费下载',
25
+ 'iphone','壁纸','购买的游戏','有什么好玩的手机游戏','诗歌','图片','视频是什么','买什么书','饮品','推荐','做饭','手机','APP',
26
+ '考研', '5G', '成都', '旅游', '深度学习','如何入门','足球', '篮球','周杰伦', '演唱会','高考','歌','法律','中医','LeetCode',
27
+ '面试','iPad','工具']
28
+
29
+ mask = df['INSTRUCTION'].str.contains('|'.join(class1))
30
+ class1_df = df[mask]
31
+
32
+ result = df[~df.isin(class1_df).all(axis=1)]
33
+
34
+ threshold = 10000
35
+ df = ds.to_pandas()
36
+ df['question_id'] = df['METADATA'].apply(lambda x: int(json.loads(x)['question_id']))
37
+ df = df.drop('SOURCE', axis=1)
38
+ df = df.drop('METADATA', axis=1)
39
+ df = df[df['upvotes'] > threshold]
40
+ filtered_df = df[df['INSTRUCTION'].str.contains('历史')]
41
+
42
+ class1 = ['魔戒','奥运','梅西','船','高中历史', '陈情令','流浪地球', '厦门','鞋','购买','高中化学','考研政治','高中政治','英语','数学','语文','解题','高二','高三','演员','周星驰','王宝强','口吻','编程','免费下载',
43
+ 'iphone','壁纸','购买的游戏','有什么好玩的手机游戏','诗歌','图片','视频是什么','买什么书','饮品','做饭','手机','APP',
44
+ '考研', '5G', '成都', '旅游', '深度学习','如何入门','足球', '篮球','周杰伦', '演唱会','高考','歌','法律','中医','LeetCode',
45
+ '面试','iPad','大罗小罗','破门绝平创历','大气二氧化碳浓度','大雁塔」','帕克太阳探测器','CPU','NBA','霍比特人','冯绍峰','历史中考',
46
+ '曼联','奥会单板','冬奥会','射手王', '浏览器的历史记录','2020赛季的F2','TES正在开创自己', 'x86','极地涡旋','百度百科',
47
+ '马刺','chrome']
48
+
49
+ mask = filtered_df['INSTRUCTION'].str.contains('|'.join(class1))
50
+ removedf = filtered_df[mask]
51
+ resultdf = filtered_df[~filtered_df.isin(removedf).all(axis=1)]
52
+ grouped_sorted_df = resultdf.sort_values(['question_id','upvotes'], ascending=[False, False])
53
+ # grouped_sorted_df['INSTRUCTION'].unique()
54
+ # grouped_sorted_df
55
+
56
+ idx = -1
57
+ with open('history.md', 'w', encoding='utf-8') as f:
58
+ for index, row in grouped_sorted_df.iterrows():
59
+ # Write the question with markdown formatting
60
+ if idx != row['question_id']:
61
+ f.write("#### " + row['INSTRUCTION'] +"\n")
62
+ idx = row['question_id']
63
+
64
+ f.write("- " +'['+str(row['upvotes'])+'] ' + row['RESPONSE']+"\n")
65
+
66
+ f.write("\n\n")