# Python数据分析基础 — 数据可视化（第2版）¶

### 王斌会 王术 电子工业出版社 2021.1¶

## 习题1¶

### 一、选择题¶

> 1:ABCD 2:CD 3:ABCD 4:A 5:D 6:B 7:A 8:A 9:D

### 二、计算题¶

（请在问题下面的空白框写出代码并执行以输出结果）

1. 下面有三组数据：

> 1, 2, 3, 4, 5

> a, b, c, d

> physics, chemistry, 1997, 2000

（1）将其写入列表中。

In [1]:

    list1=[1,2,3,4,5];list1

Out[1]:

    [1, 2, 3, 4, 5]

In [2]:

    list2=['a','b','c','d'];list2

Out[2]:

    ['a', 'b', 'c', 'd']

In [3]:

    list3=['physics','chemistry',1997,2000];list3

Out[3]:

    ['physics', 'chemistry', 1997, 2000]

（2）将其写入字典中。

In [4]:

    dict1={'num1':1,'num2':2,'num3':3,'num4':4,'num5':5};dict1

Out[4]:

    {'num1': 1, 'num2': 2, 'num3': 3, 'num4': 4, 'num5': 5}

In [5]:

    dict2={'character1':'a','character2':'b','character3':'c','character4':'d'};dict2

Out[5]:

    {'character1': 'a', 'character2': 'b', 'character3': 'c', 'character4': 'd'}

In [6]:

    dict3={'subject1':'physics','subject2':'chemistry','num1':1997,'num2':2000};dict3

Out[6]:

    {'subject1': 'physics', 'subject2': 'chemistry', 'num1': 1997, 'num2': 2000}

1. 文本数据。下面有一些文本数据：

>       name,physics,Python,math,english
>       Google,100,100,25,12
>       Facebook,45,54,44,88
>       Twitter,54,76,13,91
>       Yahoo,54,452,26,100

（1）请将其写入列表。

In [7]:

    list1=['name','physics','Python','math','english'];list1

Out[7]:

    ['name', 'physics', 'Python', 'math', 'english']

In [8]:

    list2=['Google',100,100,25,12];list2

Out[8]:

    ['Google', 100, 100, 25, 12]

In [9]:

    list3=['Facebook',45,54,44,88];list3

Out[9]:

    ['Facebook', 45, 54, 44, 88]

In [10]:

    list4=['Twitter',54,76,13,91];list4

Out[10]:

    ['Twitter', 54, 76, 13, 91]

In [11]:

    list5=['Yahoo',54,452,26,100];list5

Out[11]:

    ['Yahoo', 54, 452, 26, 100]

（2）请将其写入字典。

In [12]:

    dict1={'name':'name','subject1':'physics','subject2':'Python','subject3':'math','subject4':'english'};dict1

Out[12]:

    {'name': 'name',
     'subject1': 'physics',
     'subject2': 'Python',
     'subject3': 'math',
     'subject4': 'english'}

In [13]:

    dict2={'name':'Google','subject1':100,'subject2':100,'subject3':25,'subject4':12};dict2

Out[13]:

    {'name': 'Google',
     'subject1': 100,
     'subject2': 100,
     'subject3': 25,
     'subject4': 12}

In [14]:

    dict3={'name':'Facebook','subject1':45,'subject2':54,'subject3':44,'subject4':88};dict3

Out[14]:

    {'name': 'Facebook',
     'subject1': 45,
     'subject2': 54,
     'subject3': 44,
     'subject4': 88}

In [15]:

    dict4={'name':'Twitter','subject1':54,'subject2':76,'subject3':13,'subject4':91};dict4

Out[15]:

    {'name': 'Twitter',
     'subject1': 54,
     'subject2': 76,
     'subject3': 13,
     'subject4': 91}

In [16]:

    dict5={'name':'Yahoo','subject1':54,'subject2':452,'subject3':26,'subject4':100};dict5

Out[16]:

    {'name': 'Yahoo',
     'subject1': 54,
     'subject2': 452,
     'subject3': 26,
     'subject4': 100}