<jupyter_start><jupyter_text>分析美国总统历年在国情咨文中对国会提起的诉讼数量给出数据集的网址：http://www.presidency.ucsb.edu/data/sourequests.php<jupyter_code>import numpy as np
from matplotlib.pylab import frange
import matplotlib.pyplot as plt

fill_data = lambda x:int(x.strip() or 0)
data = np.genfromtxt('president.txt',dtype=(int,int),converters={1:fill_data},delimiter=',')
x = data[:,0]
y = data[:,1]

# 绘制数据图形以观察趋势
plt.close('all')
plt.figure(1)
plt.title('All data')
# 红色 点
plt.plot(x,y,'or')
plt.xlabel('year')
plt.ylabel('No Presndential Request')
plt.show()
# 绘制数据图形以观察趋势
plt.close('all')
plt.figure(1)
plt.title('All data')
# 红色 折线
plt.plot(x,y,'r')
plt.xlabel('year')
plt.ylabel('No Presndential Request')
plt.show()<jupyter_output><empty_output><jupyter_text>计算百分位数，来了解数据的参考<jupyter_code>perc_25 = np.percentile(y,25)
perc_50 = np.percentile(y,50)
perc_75 = np.percentile(y,75)

print '25th Percentile = %0.2f' % (perc_25)
print '50th Percentile = %0.2f' % (perc_50)
print '75th Percentile = %0.2f' % (perc_75)
# 将这些百分位数添加到之前生成的图形
# 绘制数据图形以观察趋势
plt.close('all')
plt.figure(1)
plt.title('All data')
# 红色 折线
plt.plot(x,y,'or')
plt.xlabel('year')
plt.ylabel('No Presndential Request')
plt.axhline(perc_25,label='25th perc',c='r')
plt.axhline(perc_50,label='50th perc',c='g')
plt.axhline(perc_75,label='75th perc',c='b')
plt.legend(loc='best')
plt.show()<jupyter_output><empty_output><jupyter_text>在图形中检查是否存在异常点  使用mask函数删除异常点  删除异常点最小的0 最大值 54<jupyter_code>y_masked = np.ma.masked_where(y==0,y)
y_masked = np.ma.masked_where(y_masked==54,y_masked)
# 删除异常点后重新绘图
plt.figure(2)
plt.title('Masked data')
plt.plot(x,y,'or')
plt.xlabel('year')
plt.ylabel('No presedential Request')
plt.ylim(0,60)

# 绘制
plt.axhline(perc_25,label='25th perc',c='r')
plt.axhline(perc_50,label='50th perc',c='g')
plt.axhline(perc_75,label='75th perc',c='m')
plt.legend(loc='best')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1871002132196162, 'fraction_numerical': 0.037846481876332626, 'mean_word_length': 8.15609756097561, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '633884', 'license': 'Apache-2.0', 'n_tokens_mistral': 1010, 'n_tokens_neox': 979, 'n_words': 116, 'path': 'data_analysis/single_variable.ipynb', 'repo_name': 'Roc-J/Python_data_science', 'size': '1876'}