单词:
1.series[’sɪriz] n一连串; 一系列 系列节目(同音Siri apple哈哈)
In [2]:
import pandas as pd
In [5]:
ufo = pd.read_table('http://bit.ly/uforeports',sep=',')
"""
由于uforeports是.csv文件,所以可以用专门读取csv文件的方法进行读取
.csv文件 逗号分隔符文件
ufo = pd.read_csv('http://bit.ly/uforeports')
"""
ufo1 = pd.read_csv('http://bit.ly/uforeports')
In [4]:
ufo.head()
Out[4]:
In [6]:
ufo1.head()
#测试后结果一样 哈哈哈。。。。
Out[6]:
In [7]:
type(ufo)
#被pandas读取后文件的类型是DataFrame类型
Out[7]:
In [9]:
#DataFrame类型数据进行操作
ufo['City']
Out[9]:
In [10]:
type(ufo['City']) #由此可以看出DataFrame类型 是由多个 Series类构成的
Out[10]:
In [11]:
ufo.City #这种方式比 ufo['City'] 快
Out[11]:
In [12]:
ufo.Colors Reported #如果名字中有空格这样访问会出错误
In [13]:
ufo['Colors Reported'] # 颜色 报告【颜色表示】
Out[13]:
In [14]:
ufo.shape
Out[14]:
In [15]:
'ab' + 'cd'
Out[15]:
In [16]:
#Series 也有类似的特性
ufo.City + ufo.State
Out[16]:
In [18]:
ufo.City + ', ' + ufo.State
Out[18]:
In [21]:
ufo.Location = ufo.City + ', ' + ufo.State #没有作用
In [22]:
ufo.head()
Out[22]:
In [25]:
ufo.Location
Out[25]:
In [23]:
#当要创建新一栏时并且添加到ufo的DataFrame中去,必须使用如下形式
ufo['Location'] = ufo.City + ', ' + ufo.State
In [24]:
ufo.head()
Out[24]: