import sys
import requests
from io import StringIO
import seaborn as sns # for data visualization
sns.set()
# To just take a file from https://norvig.com/big.txt
fin = StringIO(requests.get('https://norvig.com/big.txt').content.decode('utf8'))
num_symbols, num_bytes = [], []
for line in fin:
# Get size of string in bytes.
num_bytes.append(sys.getsizeof(line))
# Get no. of chars in string
num_symbols.append(len(line))
# Plot the graph.
sns.distplot(num_symbols)
# Plot the other graph.
sns.set()
sns.distplot(num_bytes)
您可以对文件内容使用[Python 3.Docs]: class collections.Counter([iterable-or-mapping]):
hist是一种映射,其中每个键都是文本中遇到的字节([0..255]),对应的值是其出现次数
试试这个:
最可能的情况是,将它们绘制在一起会提供更多信息,请尝试:
相关问题 更多 >
编程相关推荐