Update 数据提取统计.md

main
pxskm4tvn 2 months ago
parent 7d74b60986
commit 9a102b32cc

@ -1,27 +1,25 @@
```javascript const fs = require('fs');
const fs = require('fs'); const lodash = require('lodash');
const lodash = require('lodash'); const csv = require('fast-csv');
const csv = require('fast-csv');
// 读取CSV文件跳过有问题的行并给出警告
// 读取CSV文件跳过有问题的行并给出警告 csv.parseFile('chat.txt', { headers: true }, (err, data) => {
csv.parseFile('chat.txt', { headers: true }, (err, data) => { if (err) throw err;
if (err) throw err; const keyword = 'ai';
const keyword = 'ai'; const keywordData = data.filter(item => item.chat.includes(keyword));
const keywordData = data.filter(item => item.chat.includes(keyword)); const wordCounts = lodash.countBy(data, 'chat');
const wordCounts = lodash.countBy(data, 'chat'); const top8Common = lodash.takeOrdered(wordCounts, 8, lodash.identity);
const top8Common = lodash.takeOrdered(wordCounts, 8, lodash.identity);
const stats = {
const stats = { Keyword: keyword,
Keyword: keyword, Count: keywordData.length,
Count: keywordData.length, };
};
const results = {
const results = { stats: [stats],
stats: [stats], top8: top8Common,
top8: top8Common, keywordData: keywordData,
keywordData: keywordData, };
};
fs.writeFileSync('statistics.json', JSON.stringify(results, null, 2), 'utf-8');
fs.writeFileSync('statistics.json', JSON.stringify(results, null, 2), 'utf-8'); });
});
```

Loading…
Cancel
Save