词频直方图

博客主要介绍了如何计算词频并绘制词频直方图,指出由于词频极差大,采用累积概率分布图能更清晰地展示情况。强调matplotlib库在数据可视化中的重要性。
摘要由CSDN通过智能技术生成

词频直方图

算词频

import nltk
#加载Gutenberg语料库
from nltk.corpus import gutenberg
gutenberg.fileids()
['austen-emma.txt',
 'austen-persuasion.txt',
 'austen-sense.txt',
 'bible-kjv.txt',
 'blake-poems.txt',
 'bryant-stories.txt',
 'burgess-busterbrown.txt',
 'carroll-alice.txt',
 'chesterton-ball.txt',
 'chesterton-brown.txt',
 'chesterton-thursday.txt',
 'edgeworth-parents.txt',
 'melville-moby_dick.txt',
 'milton-paradise.txt',
 'shakespeare-caesar.txt',
 'shakespeare-hamlet.txt',
 'shakespeare-macbeth.txt',
 'whitman-leaves.txt']
#挑选简·奥斯丁的《爱玛》
emma=nltk.corpus.gutenberg.words('austen-emma.txt')
type(emma)
nltk.corpus.reader.util.StreamBackedCorpusView
len(emma)
192427
#每个单词平均被使用的次数
len(emma)/len(set(emma))
24.63538599411087
len(set(emma))
7811
sorted(set(emma))#生成词汇列表,在排序中,大写在小写之前,依ANSIC码排序
['!',
 '!"',
 '!"--',
 "!'",
 "!'--",
 '!)--',
 '!--',
 '!--"',
 '!--(',
 '!--`',
 '"',
 '"\'',
 '"--',
 '"`',
 '&',
 "'",
 "'--",
 "';",
 '(',
 ')',
 '),',
 ')--',
 ').',
 ').--',
 ');--',
 ',',
 ',"',
 ',"--',
 ",'",
 ',\'"',
 ',)',
 ',--',
 ',--"',
 '-',
 '--',
 '--"',
 '--(',
 '--,',
 '----',
 '----------,',
 "--------.'",
 '--.',
 '--."',
 "--.'",
 '--:',
 '--`',
 '.',
 '."',
 '."--',
 ".'",
 '.\'"',
 ".'--",
 ".'--`",
 '.)',
 '.,',
 '.,"',
 ".,'",
 '.--',
 '.--"',
 '.--`',
 '.]',
 '000',
 '10',
 '1816',
 '23rd',
 '24th',
 '26th',
 '28th',
 '7th',
 '8th',
 ':',
 ':"',
 ':"--',
 ":'",
 ":'--",
 ':--',
 ':--"',
 ';',
 ';"',
 ';"--',
 ";'",
 ";'--",
 ';--',
 ';--"',
 '?',
 '?"',
 '?"--',
 '?"--"',
 "?'",
 '?\'"',
 '?)--',
 '?--',
 '?--"',
 '?--(',
 'A',
 'Abbey',
 'Abbots',
 'Abdy',
 'Abominable',
 'About',
 'Absence',
 'Absolute',
 'Absolutely',
 'Absurd',
 'According',
 'Accordingly',
 'Acquit',
 'Actually',
 'Adelaide',
 'Adopt',
 'After',
 'Agreed',
 'Agricultural',
 'Ah',
 'Aladdin',
 'Alas',
 'Alderneys',
 'All',
 'Almane',
 'Almost',
 'Although',
 'Altogether',
 'Always',
 'Am',
 'Ambition',
 'Amiable',
 'An',
 'And',
 'Angry',
 'Anna',
 'Anne',
 'Another',
 'Anxious',
 'Any',
 'Anywhere',
 'Apologies',
 'Approve',
 'April',
 'Are',
 'Arthur',
 'As',
 'Assured',
 'Astley',
 'Astonished',
 'At',
 'August',
 'Augusta',
 'Aunt',
 'Austen',
 'Aye',
 'Bad',
 'Balls',
 'Baly',
 'Barnes',
 'Baronne',
 'Bates',
 'Bateses',
 'Bath',
 'Be',
 'Bear',
 'Beautiful',
 'Beavers',
 'Before',
 'Beg',
 'Behold',
 'Being',
 'Believe',
 'Bella',
 'Besides',
 'Better',
 'Between',
 'Beyond',
 'Bickerton',
 'Bird',
 'Birmingham',
 'Birth',
 'Bless',
 'Blessed',
 'Boarding',
 'Bond',
 'Books',
 'Both',
 'Bought',
 'Box',
 'Bragge',
 'Bragges',
 'Braithwaites',
 'Break',
 'Bristol',
 'Broadway',
 'Broadwood',
 'Brother',
 'Brown',
 'Brunswick',
 'Business',
 'Busy',
 'But',
 'By',
 'C',
 'CHAPTER',
 'CHARADE',
 'CHURCHILL',
 'Call',
 'Campbell',
 'Campbells',
 'Can',
 'Candles',
 'Cannot',
 'Captain',
 'Caroline',
 'Catherine',
 'Cautious',
 'Ceremonies',
 'Certain',
 'Certainly',
 'Charming',
 'Children',
 'Chili',
 'Christian',
 'Christmas',
 'Church',
 'Churchill',
 'Churchills',
 'Chuse',
 'Circumstances',
 'Clara',
 'Clayton',
 'Clifton',
 'Cobham',
 'Cole',
 'Coles',
 'Colonel',
 'Come',
 'Command',
 'Common',
 'Compare',
 'Compliments',
 'Composure',
 'Compressed',
 'Comtesse',
 'Conceive',
 'Concession',
 'Conjecture',
 'Consider',
 'Considering',
 'Contrary',
 'Cooper',
 'Could',
 'Cowper',
 'Cox',
 'Coxe',
 'Coxes',
 'Cramer',
 'Cromer',
 'Crown',
 'DEAR',
 'Dancing',
 'Dating',
 'Day',
 'Dear',
 'Dearer',
 'Deceived',
 'December',
 'Decidedly',
 'Delighted',
 'Delightful',
 'Depend',
 'Did',
 'Difference',
 'Dining',
 'Dinner',
 'Dirty',
 'Disingenuousness',
 'Disputable',
 'Dixon',
 'Dixons',
 'Do',
 'Does',
 'Don',
 'Donwell',
 'Dorking',
 'Dr',
 'Dreadful',
 'Dublin',
 'During',
 'E',
 'Early',
 'Easter',
 'Either',
 'Elegant',
 'Elizabeth',
 'Elton',
 'Eltons',
 'Em',
 'Emma',
 'Encouragement',
 'End',
 'Engaged',
 'England',
 'English',
 'Enscombe',
 'Escape',
 'Especially',
 'Even',
 'Ever',
 'Every',
 'Exactly',
 'Excellent',
 'Excellently',
 'Except',
 'Excepting',
 'Excuse',
 'Exquisite',
 'Extracts',
 'Extraordinary',
 'Extremely',
 'F',
 'FINIS',
 'Fairfax',
 'Fancying',
 'Farm',
 'Farmer',
 'February',
 'Fetch',
 'Find',
 'Fine',
 'Finesse',
 'Five',
 'For',
 'Forcing',
 'Ford',
 'Forest',
 'Former',
 'Fortunate',
 'Fortunately',
 'Fortune',
 'Four',
 'Fourteen',
 'Frank',
 'French',
 'Friday',
 'From',
 'Full',
 'Garrick',
 'General',
 'Genlis',
 'George',
 'Gilbert',
 'Gilberts',
 'Give',
 'Go',
 'God',
 'Goddard',
 'Going',
 'Goldsmith',
 'Gone',
 'Good',
 'Graham',
 'Grandmama',
 'Grandpapa',
 'Granted',
 'Gratifying',
 'Great',
 'Green',
 'Grove',
 'Ha',
 'Had',
 'Half',
 'Hall',
 'Handsome',
 'Hannah',
 'Happier',
 'Happily',
 'Happy',
 'Harriet',
 'Harry',
 'Hart_',
 'Hartfield',
 'Has',
 'Have',
 'Having',
 'Hawkins',
 'Hazle',
 'He',
 'Heaven',
 'Heavens',
 'Henceforward',
 'Henry',
 'Her',
 'Here',
 'Hetty',
 'High',
 'Highbury',
 'Hill',
 'Him',
 'His',
 'Hitherto',
 'Hodges',
 'Holyhead',
 'How',
 'However',
 'Hughes',
 'Hum',
 'Human',
 'Humph',
 'Hush',
 'Hymen',
 'I',
 'II',
 'III',
 'IV',
 'IX',
 'If',
 'Ill',
 'Imagine',
 'Immediately',
 'Impossible',
 'Impropriety',
 'Imprudent',
 'In',
 'Increase',
 'Indeed',
 'Indifferent',
 'Indignation',
 'Inn',
 'Instances',
 'Instead',
 'Insufferable',
 'Interference',
 'Intimacy',
 'Invite',
 'Ireland',
 'Irish',
 'Is',
 'Isabella',
 'It',
 'Italian',
 'Its',
 'JULY',
 'James',
 'Jane',
 'January',
 'Jeffereys',
 'John',
 'Judge',
 'July',
 'June',
 'Just',
 'K',
 'Keep',
 'Kindled',
 'King',
 'Kings',
 'Kingston',
 'Kitty',
 'Knightley',
 'Knightleys',
 'La',
 'Ladies',
 'Lady',
 'Lane',
 'Langham',
 'Larkins',
 'Late',
 'Later',
 'Latterly',
 'Leave',
 'Let',
 'Letters',
 'Liable',
 'Lieut',
 'Like',
 'Little',
 'Lively',
 'Living',
 'London',
 'Long',
 'Look',
 'Lord',
 'Lords',
 'Low',
 'M',
 'MADAM',
 'MY',
 'Ma',
 'Madam',
 'Madame',
 'Madeira',
 'Madness',
 'Making',
 'Man',
 'Manchester',
 'Manners',
 'Many',
 'Maple',
 'March',
 'Mark',
 'Marriage',
 'Married',
 'Martin',
 'Martins',
 'Master',
 'Matrimony',
 'May',
 'Me',
 'Men',
 'Mermaids',
 'Methodical',
 'Michaelmas',
 'Mickleham',
 'Middling',
 'Midsummer',
 'Might',
 'Mill',
 'Milmans',
 'Mine',
 'Miniatures',
 'Miss',
 'Misses',
 'Mistake',
 'Mistresses',
 'Mitchell',
 'Monday',
 'More',
 'Morning',
 'Most',
 'Mr',
 'Mrs',
 'Much',
 'Must',
 'My',
 'Myself',
 'Mystery',
 'N',
 'Name',
 'Nash',
 'Natural',
 'Nature',
 'Nay',
 'Neither',
 'Neptune',
 'Never',
 'News',
 'No',
 'Nobody',
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值