使用微信公众号数据进行分析
import pandas as pd
import numpy as np
%matplotlib inline
%matplotlib notebook
import matplotlib.pyplot as plt
from numpy import *
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['SimHei']
import trees
import treePlotter
fr = open('lenses.txt')
lenses = [inst.strip().split('\t') for inst in fr.readlines()]
lensesLabels=['标题吸引', '文章置顶', '公司信息', '公司政策','影响范围大']
lensesLabels
lensesLabels2 = lensesLabels[:]
lensesTree = trees.createTree(lenses,lensesLabels)
lensesTree
{'标题吸引': {'N': {'文章置顶': {'N': {'影响范围大': {'N': {'公司信息': {'N': {'公司政策': {'N': '<1K',
'Y': '<1K'}},
'Y': {'公司政策': {'N': '<1K', 'Y': '<1K'}}}},
'Y': {'公司信息': {'N': {'公司政策': {'N': '<1K', 'Y': '<1K'}},
'Y': {'公司政策': {'N': '<1K', 'Y': '<1K'}}}}}},
'Y': {'影响范围大': {'N': {'公司信息': {'N': '>1K',
'Y': {'公司政策': {'<1K': '<1K', '>1K': '>1K'}}}},
'Y': {'公司政策': {'N': {'公司信息': {'N': '>1K', 'Y': '>1K'}},
'Y': {'公司信息': {'<1K': '<1K', '>1K': '>1K'}}}}}}}},
'Y': {'文章置顶': {'N': '>1K',
'Y': {'公司政策': {'N': {'影响范围大': {'N': {'公司信息': {'<1K': '<1K', '>1K': '>1K'}},
'Y': {'公司信息': {'<1K': '<1K', '>1K': '>1K'}}}},
'Y': {'影响范围大': {'<1K': '<1K', '>1K': '>1K'}}}}}}}}
treePlotter.createPlot(lensesTree)