<jupyter_start><jupyter_text>数据分析实践-手机篇（二）  数据调查收集手机市场在售手机静态资料，数据来源京东，apple.com.cn等，以CSV文件存储。 数据源- [华为手机官网](https://consumer.huawei.com/cn/phones/?ic_medium=hwdc&ic_source=corp_header_consumer)- [小米商城](https://www.mi.com/index.html)  外形分析比较各型手机的长度，宽度，厚度，重量等信息。<jupyter_code>import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
%matplotlib widget
matplotlib.rcParams['font.family'] = ['DengXian', 'sans-serif']<jupyter_output><empty_output><jupyter_text>1. 读入csv文件<jupyter_code>fn = 'phone_data2.csv'
df = pd.read_csv(fn)
df.head()
fig, ax = plt.subplots()
CPU与颜色都是分类变量，首先建立映射。
[pandas - Categorical data](https://pandas.pydata.org/docs/user_guide/categorical.html)
df['CPU']<jupyter_output><empty_output><jupyter_text>CPU列的内容如上，df['CPU'].unique()方法的返回值中包含nan，<jupyter_code>c = df['CPU'].astype('category')<jupyter_output><empty_output><jupyter_text>在数据准备好后，开始制图。参考带有图例的散点图，每次绘制一种CPU的散点。筛选CPU列包含A13的所有行？<jupyter_code>ax.cla()
for i in range(len(c.cat.categories)):
    ax.scatter('长', '宽', s = '重', c = 'C%d' % (i+1), alpha = 0.25, 
               data = df[df['CPU'] == c.cat.categories[i]],
               label = c.cat.categories[i])
ax.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17394888705688377, 'fraction_numerical': 0.006595218466611707, 'mean_word_length': 6.832258064516129, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 3, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '600023', 'license': 'MIT', 'n_tokens_mistral': 609, 'n_tokens_neox': 640, 'n_words': 57, 'path': 'phone_2.ipynb', 'repo_name': 'darkeggler/data_visualization_notebooks', 'size': '1213'}