<jupyter_start><jupyter_text>FBI 枪支数据该数据来自联邦调查局 (FBI) 的全国即时犯罪背景调查系统 (NICS)。NICS 用于确定潜在买家是否有资格购买枪支或爆炸物。枪支店可以进入这个系统，以确保每位客户没有犯罪记录或符合资格购买。该数据已经收纳了来自 census.gov 的州级数据作为补充数据。NICS 数据在一个 xlsx 文件格式的一个表格中，它包含了按照月份 (month)、州 (state) 、类型 (type) 统计的武器调查数量 (the number of firearm checks) ;美国的人口普查数据 (U.S. census data) 储存在一个 csv 文件中。它包含了州级的几个变量，每个州的大多数变量在 2016 年只有一个数据点，但一些变量有一年以上的数据。  1.查看，观察数据<jupyter_code>df_census = pd.read_csv('U.S. Census Data.csv')
df_census.head()
df_gun = pd.read_excel('gun_data.xlsx')
df_gun.head()
df_census.info()
df_census.Fact.values
df_census['Fact Note'].unique()
df_gun.info()
states = df_gun.state.unique()
len(states), states<jupyter_output><empty_output><jupyter_text>可以看出来数据比较多，两个表均包含各个州的数据，所以后边仅挑出New York的数据做对照分析，以方便得出结论  数据清理<jupyter_code>df_gun_new_york = df_gun.query("state == 'New York'")
df_gun_new_york.info()
df_gun_new_york.to_csv('gun_data_new_york.csv', index=False)
df_census.columns
df_census_new_york = df_census.drop(['Alabama', 'Alaska', 'Arizona', 'Arkansas',
       'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida',
       'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas',
       'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts',
       'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana',
       'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico',
        'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma',
       'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina',
       'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia',
       'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'], axis=1)
df_census_new_york.info()
df_census_new_york.rename(index=str, columns={'New York': 'data'}, inplace=True)
df_census_new_york.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
Index: 85 entries, 0 to 84
Data columns (total 3 columns):
Fact         80 non-null object
Fact Note    28 non-null object
data         65 non-null object
dtypes: object(3)
memory usage: 2.7+ KB<jupyter_text>删除纽约数据为空的行<jupyter_code>df_census_new_york = df_census_new_york[df_census_new_york.data.notnull()]
df_census_new_york.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
Index: 65 entries, 0 to 64
Data columns (total 3 columns):
Fact         65 non-null object
Fact Note    16 non-null object
data         65 non-null object
dtypes: object(3)
memory usage: 4.5+ KB
{'fraction_non_alphanumeric': 0.14564315352697096, 'fraction_numerical': 0.014937759336099586, 'mean_word_length': 6.029154518950437, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '401379', 'license': 'Apache-2.0', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1149, 'n_words': 187, 'path': 'ncis-and-census-data/.ipynb_checkpoints/Guns-checkpoint.ipynb', 'repo_name': 'AprilYoungs/analyze_basic', 'size': '2410'}