From 9a102b32cc00c664dc557bee15963dcf5955c474 Mon Sep 17 00:00:00 2001 From: pxskm4tvn <2836285168@qq.com> Date: Wed, 18 Sep 2024 00:01:34 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E6=95=B0=E6=8D=AE=E6=8F=90=E5=8F=96?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 数据提取统计.md | 52 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/数据提取统计.md b/数据提取统计.md index c3f9ea8..91c445d 100644 --- a/数据提取统计.md +++ b/数据提取统计.md @@ -1,27 +1,25 @@ -```javascript -const fs = require('fs'); -const lodash = require('lodash'); -const csv = require('fast-csv'); - -// 读取CSV文件,跳过有问题的行并给出警告 -csv.parseFile('chat.txt', { headers: true }, (err, data) => { - if (err) throw err; - const keyword = 'ai'; - const keywordData = data.filter(item => item.chat.includes(keyword)); - const wordCounts = lodash.countBy(data, 'chat'); - const top8Common = lodash.takeOrdered(wordCounts, 8, lodash.identity); - - const stats = { - Keyword: keyword, - Count: keywordData.length, - }; - - const results = { - stats: [stats], - top8: top8Common, - keywordData: keywordData, - }; - - fs.writeFileSync('statistics.json', JSON.stringify(results, null, 2), 'utf-8'); -}); -``` \ No newline at end of file +const fs = require('fs'); +const lodash = require('lodash'); +const csv = require('fast-csv'); + +// 读取CSV文件,跳过有问题的行并给出警告 +csv.parseFile('chat.txt', { headers: true }, (err, data) => { + if (err) throw err; + const keyword = 'ai'; + const keywordData = data.filter(item => item.chat.includes(keyword)); + const wordCounts = lodash.countBy(data, 'chat'); + const top8Common = lodash.takeOrdered(wordCounts, 8, lodash.identity); + + const stats = { + Keyword: keyword, + Count: keywordData.length, + }; + + const results = { + stats: [stats], + top8: top8Common, + keywordData: keywordData, + }; + + fs.writeFileSync('statistics.json', JSON.stringify(results, null, 2), 'utf-8'); +});