defset_x(num): # 但是不能在函数内部改变全局变量 # 这里的x是一个新生成的,只在函数内生效的局部变量 x = num # => 43 print(x) # => 43
defset_global_x(num): # 如果想要在函数内部改变全局变量,需要通过global声明 global x print(x) # => 5 x = num # global var x is now set to num print(x) # => num
1
get_x(6)
6
5
1 2
set_x(6) print(x)
6
5
1 2
set_global_x(6) print(x)
5
6
6
1 2 3 4 5 6 7 8 9 10 11
# python支持头等函数 # 简单来讲,return的函数就是上层函数的头等函数 defcreate_adder(x): # suber就是简单的嵌套定义了一个函数 defsuber(z): return x - z n = suber(5) # adder参与返回值,是头等函数 defadder(y): return n + y return adder
some_var = 5 # python通过缩进来对代码进行分段(连续同缩进量的代码可以看作在一个大括号里,空行、注释行自动忽略) # 一个缩进应该是4个空格,不是制表符 if some_var > 10: print("some_var is totally bigger than 10.") elif some_var < 10: # 可选 print("some_var is smaller than 10.") else: # 可选 print("some_var is indeed 10.")
some_var is smaller than 10.
1 2 3 4 5
# for item in list # 迭代取出list中的所有item进行计算 for animal in ["dog", "cat", "mouse"]: # You can use format() to interpolate formatted strings print("{} is a mammal".format(animal))
dog is a mammal
cat is a mammal
mouse is a mammal
1 2 3
# range(n)方法返回一个list,[0,1,2,...,n-1] for i in range(4): print(i)
0
1
2
3
1 2 3
# range(start,end)返回一个list,[start, start+1, ..., end-1] for i in range(4, 8): print(i)
4
5
6
7
1 2 3
# range(start,end,step)返回一个list,[start, start+step, ..., (直到>=end)] for i in range(4, 8, 2): print(i)
4
6
1 2 3 4 5
# while循环,持续迭代知道不满足判断条件 x = 0 while x < 4: print(x) x += 1# Shorthand for x = x + 1
0
1
2
3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# 可以通过try except来处理异常(避免报错直接退出) try: # raise方法,可以手动报错 raise IndexError("This is an index error") except IndexError as e: # pass保留字代表这一行啥不也干 pass except (TypeError, NameError): # 如果有多个except,可以同时执行 pass # 可选,如果try的代码块没有问题,则执行 else: print("All good!") # 可选,不管有没有问题,都会执行finally中的代码块 finally: print("We can clean up resources here")
We can clean up resources here
1 2 3 4 5 6 7 8 9 10
# 通常open(fileName)之后,需要调用close方法来释放内存 # 为了避免代码出错,产生内存垃圾,需要 # try: # open # finally: # close # 也可以通过with open() as name:来进行声明,该声明块结束后会自动close with open("myfile.txt") as f: for line in f: print(line)
1 2 3 4 5 6
# Python提供一种基础抽象方法叫做Iterable(可迭代的) # 一个iterable对象,可以被当作sequence对待 # range函数返回的对象其实就是iterable filled_dict = {"one": 1, "two": 2, "three": 3} our_iterable = filled_dict.keys() print(our_iterable) # => dict_keys(['one', 'two', 'three']). This is an object that implements our Iterable interface.
dict_keys(['one', 'two', 'three'])
1 2 3
# iterable 可迭代,比如放到for循环中 for i in our_iterable: print(i)
one
two
three
1 2 3
# 但是无法通过index取出其中的数值 # 会报错 our_iterable[0]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-114-138f56ebc699> in <module>()
1 # 但是无法通过index取出其中的数值
2 # 会报错
----> 3 our_iterable[0]
TypeError: 'dict_keys' object does not support indexing
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-48-17aa7cb5f29d> in <module>()
1 # 访问一个没有赋值过的变量名,会抛出异常
2 # 直接看console中的输出来了解异常原因
----> 3 some_unknown_var
NameError: name 'some_unknown_var' is not defined
1 2 3 4
# if 可以用来作为一种表达式 # a if b else c 意为 b为True取a,b为False取c hoo = "yahoo!"if3 > 2else2# => "yahoo!" hoo
# list有append函数,可以在末尾添加item li.append(1) # li is now [1] li.append(2) # li is now [1, 2] li.append(4) # li is now [1, 2, 4] li.append(3) # li is now [1, 2, 4, 3] # pop函数可以删除list中的最后一个元素 li.pop() # => 3 and li is now [1, 2, 4] # 还是把3放回去吧 li.append(3) # li is now [1, 2, 4, 3] again.
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-53-9bf3eba2f737> in <module>()
1 # 如果index访问的item超出list长度,会抛出异常
----> 2 li[4] # Raises an IndexError
IndexError: list index out of range
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-58-0f5f01941ba3> in <module>()
1 # remove方法调用时,如果没有对应value的item,则会报错
----> 2 li.remove(100)
ValueError: list.remove(x): x not in list
1 2 3
# insert(index, value)可以在list中的index处插入值为value的item li.insert(1, 2) # li is now [1, 2, 3] again li
[1, 2, 3]
1 2 3 4
# index(value)方法可以在list中进行查询,返回值为value的item的index li.index(2) # => 1 # 没有的话就报错 li.index(4) # Raises a ValueError as 4 is not in the list
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-60-4520a794cb71> in <module>()
2 li.index(2) # => 1
3 # 没有的话就报错
----> 4 li.index(4) # Raises a ValueError as 4 is not in the list
ValueError: 4 is not in list
# 可以对tuple进行解压,分别赋值给变量 a, b, c = (1, 2, 3) # a = 1, b = 2 and c = 3 # 还可以进行扩展拆包 a, *b, c = (1, 2, 3, 4) # a = 1, b = [2, 3] and c = 4 # 如果你不写括号,tuple也会自动生成 d, e, f = 4, 5, 6 # 交换两个变量的值 e, d = d, e # d is now 5 and e is now 4
# setdefault方法可以给不存在的key赋值 # 如果该键值对(key:value)已存在,则不生效 filled_dict.setdefault("five", 5) # filled_dict["five"] is set to 5 filled_dict.setdefault("five", 6) # filled_dict["five"] is still 5
5
1 2 3 4
# 在dictionary中增加键值对,可以使用update方法 filled_dict.update({"four":4}) # => {"one": 1, "two": 2, "three": 3, "four": 4} # 直接对不存在的key 进行赋值,也可以实现键值对的增加 filled_dict["four"] = 4# another way to add to dict
1 2
# 通过del方法可以删除对应key的键值对 del filled_dict["one"] # Removes the key "one" from filled dict
# 赋值是单等号 =,相等判断是双等号 == # 还有一个相等判断保留字 is # is 判断前后两者是否指向同一个对象(如果是两个对象,就算值相同,也会返回False) # == 只判断值是否相同 a = [1, 2, 3, 4] # Point a at a new list, [1, 2, 3, 4] b = a # Point b at what a is pointing to b is a # => True, a and b refer to the same object b == a # => True, a's and b's objects are equal b = [1, 2, 3, 4] # Point b at a new list, [1, 2, 3, 4] b is a # => False, a and b do not refer to the same object b == a # => True, a's and b's objects are equal
1 2 3
# 通过‘或者“可以创建string "This is a string." 'This is also a string.'
# 一个string可以看作是一个char的list "This is a string"[0] # => 'T'
'T'
1 2
# len()是一个保留函数,可以计算list的长度 len("This is a string") # => 16
16
1 2
# python中的string对象,有.format方法,可以用来对该string进行格式化操作 "{} can be {}".format("Strings", "interpolated") # => "Strings can be interpolated"
'Strings can be interpolated'
1 2
# 可以通过在大括号{}中添加format参数的index来进行填充指定 "{0} be nimble, {0} be quick, {0} jump over the {1}".format("Jack", "candle stick")
'Jack be nimble, Jack be quick, Jack jump over the candle stick'
1 2
# 也可以给format中的参数命名,来代替index. "{name} wants to eat {food}".format(name="Bob", food="lasagna")
'Bob wants to eat lasagna'
1 2
# 如果需要兼容python2,老版的format写法如下 "%s can be %s the %s way" % ("Strings", "interpolated", "old")
'Strings can be interpolated the old way'
1 2 3 4 5
# 在python3.6之后的版本中,可以在string前加f来进行format操作 name = "Reiko" f"She said her name is {name}."# => "She said her name is Reiko" # 在大括号中,也可以调用python的方法 f"{name} is {len(name)} characters long."
# python有多个版本,Python 2.7到Python 3.x,Python提供了__future__模块,把3.x新版本的特性导入到当前版本 # 这一句的意思是除法按照python3来: # 区别就是python2里边10/3=3,python3里边10/3=3.3333333333333335 from __future__ import division # 导入numpy中的随机函数randn from numpy.random import randn # 到处numpy包,并命名为np import numpy as np # 导入os包 import os # 导入matplotlib.pyplot,并命名为plt,主要用于绘图 import matplotlib.pyplot as plt # 导入pandas包,并命名为pd import pandas as pd # 利用rc方法,plt.rc('figure',figsize=(10,6))全局默认图像大小为10X6 plt.rc('figure', figsize=(10, 6)) # numpy set print options 小数点后4位 np.set_printoptions(precision=4)
1 2 3 4 5 6 7
# 导入json包 import json # 赋值 path = 'ch02/usagov_bitly_data2012-03-16-1331923249.txt' # 逐行遍历path文件中的数据,通过按照json格式读取,然后每一行的作为一个item组成list lines = open(path).readlines() records = [json.loads(line) for line in lines]
1 2 3 4 5 6 7 8 9
# 导入pandas的两个方法 from pandas import DataFrame, Series # 导入pandas包,并命名为pd import pandas as pd # 建立DataFrame对象,把key作为列名,value作为值填到一张表中,没有的键值对会用NaN(空值)填充 # 并自动生成索引,就是左边的0 1 2 3... frame = DataFrame(records) # 打印出来看一下(这是一个pandas对象) print(frame)
_heartbeat_ a \
0 NaN Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKi...
1 NaN GoogleMaps/RochesterNY
2 NaN Mozilla/4.0 (compatible; MSIE 8.0; Windows NT ...
3 NaN Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8)...
4 NaN Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKi...
5 NaN Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKi...
6 NaN Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1...
7 NaN Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/2...
8 NaN Opera/9.80 (X11; Linux zbov; U; en) Presto/2.1...
9 NaN Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKi...
10 NaN Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2)...
11 NaN Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4...
12 NaN Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2)...
13 1.331923e+09 NaN
14 NaN Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US...
15 NaN Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1...
16 NaN Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1...
17 NaN Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; r...
18 NaN GoogleMaps/RochesterNY
19 NaN Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKi...
20 NaN Mozilla/5.0 (compatible; MSIE 9.0; Windows NT ...
21 NaN Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6...
22 NaN Mozilla/4.0 (compatible; MSIE 8.0; Windows NT ...
23 NaN Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3)...
24 NaN Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES...
25 NaN Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1...
26 NaN Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1...
27 NaN Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8)...
28 NaN Mozilla/5.0 (iPad; CPU OS 5_0_1 like Mac OS X)...
29 NaN Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X...
... ... ...
3530 NaN Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1...
3531 NaN Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6...
3532 NaN Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2)...
3533 NaN Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) A...
3534 NaN Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8)...
3535 NaN Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/...
3536 NaN Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; e...
3537 NaN Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2)...
3538 NaN Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Ma...
3539 NaN Mozilla/5.0 (compatible; Fedora Core 3) FC3 KDE
3540 NaN Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKi...
3541 NaN Mozilla/5.0 (X11; U; OpenVMS AlphaServer_ES40;...
3542 NaN Mozilla/5.0 (compatible; MSIE 9.0; Windows NT ...
3543 1.331927e+09 NaN
3544 NaN Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0.1) ...
3545 NaN Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2)...
3546 NaN Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Ma...
3547 NaN Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8)...
3548 NaN Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Ma...
3549 NaN Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKi...
3550 NaN Mozilla/4.0 (compatible; MSIE 8.0; Windows NT ...
3551 NaN Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKi...
3552 NaN Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US...
3553 NaN Mozilla/4.0 (compatible; MSIE 7.0; Windows NT ...
3554 NaN Mozilla/4.0 (compatible; MSIE 7.0; Windows NT ...
3555 NaN Mozilla/4.0 (compatible; MSIE 9.0; Windows NT ...
3556 NaN Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1...
3557 NaN GoogleMaps/RochesterNY
3558 NaN GoogleProducer
3559 NaN Mozilla/4.0 (compatible; MSIE 8.0; Windows NT ...
al c cy g \
0 en-US,en;q=0.8 US Danvers A6qOVH
1 NaN US Provo mwszkS
2 en-US US Washington xxr3Qb
3 pt-br BR Braz zCaLwp
4 en-US,en;q=0.8 US Shrewsbury 9b6kNl
5 en-US,en;q=0.8 US Shrewsbury axNK8c
6 pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4 PL Luban wcndER
7 bg,en-us;q=0.7,en;q=0.3 None NaN wcndER
8 en-US, en None NaN wcndER
9 pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4 None NaN zCaLwp
10 en-us,en;q=0.5 US Seattle vNJS4H
11 en-us,en;q=0.5 US Washington wG7OIH
12 en-us,en;q=0.5 US Alexandria vNJS4H
13 NaN NaN NaN NaN
14 en-us,en;q=0.5 US Marietta 2rOUYc
15 zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4 HK Central District nQvgJp
16 zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4 HK Central District XdUNr
17 en-us,en;q=0.5 US Buckfield zH1BFf
18 NaN US Provo mwszkS
19 it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4 IT Venice wcndER
20 es-ES ES Alcal zQ95Hi
21 en-us,en;q=0.5 US Davidsonville wcndER
22 en-us US Hockessin y3ZImz
23 en-us US Lititz wWiOiD
24 es-es,es;q=0.8,en-us;q=0.5,en;q=0.3 ES Bilbao wcndER
25 en-GB,en;q=0.8,en-US;q=0.6,en-AU;q=0.4 MY Kuala Lumpur wcndER
26 ro-RO,ro;q=0.8,en-US;q=0.6,en;q=0.4 CY Nicosia wcndER
27 en-US,en;q=0.8 BR SPaulo zCaLwp
28 en-us None NaN vNJS4H
29 en-us None NaN FPX0IM
... ... ... ... ...
3530 en-US,en;q=0.8 US San Francisco xVZg4P
3531 en-US None NaN wcndER
3532 en-us,en;q=0.5 US Washington Au3aUS
3533 en-us US Jacksonville b2UtUJ
3534 en-us US Frisco vNJS4H
3535 en-us US Houston zIgLx8
3536 en-US,en;q=0.5 None NaN xIcyim
3537 es-es,es;q=0.8,en-us;q=0.5,en;q=0.3 HN Tegucigalpa zCaLwp
3538 en-us US Los Angeles qMac9k
3539 NaN US Bellevue zu2M5o
3540 en-US,en;q=0.8 US Payson wcndER
3541 NaN US Bellevue zu2M5o
3542 en-us US Pittsburg y3reI1
3543 NaN NaN NaN NaN
3544 en-us,en;q=0.5 US Wentzville vNJS4H
3545 en-us,en;q=0.5 US Saint Charles vNJS4H
3546 en-us US Los Angeles qMac9k
3547 en-us US Silver Spring y0jYkg
3548 en-us US Mcgehee y5rMac
3549 sv-SE,sv;q=0.8,en-US;q=0.6,en;q=0.4 SE Sollefte eH8wu
3550 en-us US Conshohocken A00b72
3551 en-US,en;q=0.8 None NaN wcndER
3552 NaN US Decatur rqgJuE
3553 en-us US Shrewsbury 9b6kNl
3554 en-us US Shrewsbury axNK8c
3555 en US Paramus e5SvKE
3556 en-US,en;q=0.8 US Oklahoma City jQLtP4
3557 NaN US Provo mwszkS
3558 NaN US Mountain View zjtI4X
3559 en-US US Mc Lean qxKrTK
gr h hc hh kw l \
0 MA wfLQtf 1.331823e+09 1.usa.gov NaN orofrog
1 UT mwszkS 1.308262e+09 j.mp NaN bitly
2 DC xxr3Qb 1.331920e+09 1.usa.gov NaN bitly
3 27 zUtuOu 1.331923e+09 1.usa.gov NaN alelex88
4 MA 9b6kNl 1.273672e+09 bit.ly NaN bitly
5 MA axNK8c 1.273673e+09 bit.ly NaN bitly
6 77 zkpJBR 1.331923e+09 1.usa.gov NaN bnjacobs
7 NaN zkpJBR 1.331923e+09 1.usa.gov NaN bnjacobs
8 NaN zkpJBR 1.331923e+09 1.usa.gov NaN bnjacobs
9 NaN zUtuOu 1.331923e+09 1.usa.gov NaN alelex88
10 WA u0uD9q 1.319564e+09 1.usa.gov NaN o_4us71ccioa
11 DC A0nRz4 1.331816e+09 1.usa.gov NaN darrellissa
12 VA u0uD9q 1.319564e+09 1.usa.gov NaN o_4us71ccioa
13 NaN NaN NaN NaN NaN NaN
14 GA 2rOUYc 1.255770e+09 1.usa.gov NaN bitly
15 00 rtrrth 1.317318e+09 j.mp NaN walkeryuen
16 00 qWkgbq 1.317318e+09 j.mp NaN walkeryuen
17 ME x3jOIv 1.331840e+09 1.usa.gov NaN andyzieminski
18 UT mwszkS 1.308262e+09 1.usa.gov NaN bitly
19 20 zkpJBR 1.331923e+09 1.usa.gov NaN bnjacobs
20 51 ytZYWR 1.331671e+09 bitly.com NaN jplnews
21 MD zkpJBR 1.331923e+09 1.usa.gov NaN bnjacobs
22 DE y3ZImz 1.331064e+09 1.usa.gov NaN bitly
23 PA wWiOiD 1.330218e+09 1.usa.gov NaN bitly
24 59 zkpJBR 1.331923e+09 1.usa.gov NaN bnjacobs
25 14 zkpJBR 1.331923e+09 1.usa.gov NaN bnjacobs
26 04 zkpJBR 1.331923e+09 1.usa.gov NaN bnjacobs
27 27 zUtuOu 1.331923e+09 1.usa.gov NaN alelex88
28 NaN u0uD9q 1.319564e+09 1.usa.gov NaN o_4us71ccioa
29 NaN FPX0IL 1.331923e+09 1.usa.gov NaN twittershare
... ... ... ... ... ... ...
3530 CA wqUkTo 1.331908e+09 go.nasa.gov NaN nasatwitter
3531 NaN zkpJBR 1.331923e+09 1.usa.gov NaN bnjacobs
3532 DC A9ct6C 1.331926e+09 1.usa.gov NaN ncsha
3533 FL ieCdgH 1.301393e+09 go.nasa.gov NaN nasatwitter
3534 TX u0uD9q 1.319564e+09 1.usa.gov NaN o_4us71ccioa
3535 TX yrPaLt 1.331903e+09 aash.to NaN aashto
3536 NaN yG1TTf 1.331728e+09 go.nasa.gov NaN nasatwitter
3537 08 w63FZW 1.331547e+09 1.usa.gov NaN bufferapp
3538 CA qds1Ge 1.310474e+09 1.usa.gov NaN healthypeople
3539 WA zDhdro 1.331586e+09 bit.ly NaN glimtwin
3540 UT zkpJBR 1.331923e+09 1.usa.gov NaN bnjacobs
3541 WA zDhdro 1.331586e+09 1.usa.gov NaN glimtwin
3542 CA y3reI1 1.331926e+09 1.usa.gov NaN bitly
3543 NaN NaN NaN NaN NaN NaN
3544 MO u0uD9q 1.319564e+09 1.usa.gov NaN o_4us71ccioa
3545 IL u0uD9q 1.319564e+09 1.usa.gov NaN o_4us71ccioa
3546 CA qds1Ge 1.310474e+09 1.usa.gov NaN healthypeople
3547 MD y0jYkg 1.331852e+09 1.usa.gov NaN bitly
3548 AR xANY6O 1.331916e+09 1.usa.gov NaN twitterfeed
3549 24 7dtjei 1.260316e+09 1.usa.gov NaN tweetdeckapi
3550 PA yGSwzn 1.331918e+09 1.usa.gov NaN addthis
3551 NaN zkpJBR 1.331923e+09 1.usa.gov NaN bnjacobs
3552 AL xcz8vt 1.331227e+09 1.usa.gov NaN bootsnall
3553 MA 9b6kNl 1.273672e+09 bit.ly NaN bitly
3554 MA axNK8c 1.273673e+09 bit.ly NaN bitly
3555 NJ fqPSr9 1.301298e+09 1.usa.gov NaN tweetdeckapi
3556 OK jQLtP4 1.307530e+09 1.usa.gov NaN bitly
3557 UT mwszkS 1.308262e+09 j.mp NaN bitly
3558 CA zjtI4X 1.327529e+09 1.usa.gov NaN bitly
3559 VA qxKrTK 1.312898e+09 1.usa.gov NaN bitly
ll nk \
0 [42.576698, -70.954903] 1.0
1 [40.218102, -111.613297] 0.0
2 [38.9007, -77.043098] 1.0
3 [-23.549999, -46.616699] 0.0
4 [42.286499, -71.714699] 0.0
5 [42.286499, -71.714699] 0.0
6 [51.116699, 15.2833] 0.0
7 NaN 0.0
8 NaN 0.0
9 NaN 0.0
10 [47.5951, -122.332603] 1.0
11 [38.937599, -77.092796] 0.0
12 [38.790901, -77.094704] 1.0
13 NaN NaN
14 [33.953201, -84.5177] 1.0
15 [22.2833, 114.150002] 1.0
16 [22.2833, 114.150002] 1.0
17 [44.299702, -70.369797] 0.0
18 [40.218102, -111.613297] 0.0
19 [45.438599, 12.3267] 0.0
20 [37.516701, -5.9833] 0.0
21 [38.939201, -76.635002] 0.0
22 [39.785, -75.682297] 0.0
23 [40.174999, -76.3078] 0.0
24 [43.25, -2.9667] 0.0
25 [3.1667, 101.699997] 0.0
26 [35.166698, 33.366699] 0.0
27 [-23.5333, -46.616699] 0.0
28 NaN 0.0
29 NaN 1.0
... ... ...
3530 [37.7645, -122.429398] 0.0
3531 NaN 0.0
3532 [38.904202, -77.031998] 1.0
3533 [30.279301, -81.585098] 1.0
3534 [33.149899, -96.855499] 1.0
3535 [29.775499, -95.415199] 1.0
3536 NaN 0.0
3537 [14.1, -87.216698] 0.0
3538 [34.041599, -118.298798] 0.0
3539 [47.615398, -122.210297] 0.0
3540 [40.014198, -111.738899] 0.0
3541 [47.615398, -122.210297] 0.0
3542 [38.0051, -121.838699] 0.0
3543 NaN NaN
3544 [38.790001, -90.854897] 1.0
3545 [41.9352, -88.290901] 1.0
3546 [34.041599, -118.298798] 1.0
3547 [39.052101, -77.014999] 1.0
3548 [33.628399, -91.356903] 1.0
3549 [63.166698, 17.266701] 1.0
3550 [40.0798, -75.2855] 0.0
3551 NaN 0.0
3552 [34.572701, -86.940598] 0.0
3553 [42.286499, -71.714699] 0.0
3554 [42.286499, -71.714699] 0.0
3555 [40.9445, -74.07] 1.0
3556 [35.4715, -97.518997] 0.0
3557 [40.218102, -111.613297] 0.0
3558 [37.419201, -122.057404] 0.0
3559 [38.935799, -77.162102] 0.0
r t \
0 http://www.facebook.com/l/7AQEFzjSi/1.usa.gov/... 1.331923e+09
1 http://www.AwareMap.com/ 1.331923e+09
2 http://t.co/03elZC4Q 1.331923e+09
3 direct 1.331923e+09
4 http://www.shrewsbury-ma.gov/selco/ 1.331923e+09
5 http://www.shrewsbury-ma.gov/selco/ 1.331923e+09
6 http://plus.url.google.com/url?sa=z&n=13319232... 1.331923e+09
7 http://www.facebook.com/ 1.331923e+09
8 http://www.facebook.com/l.php?u=http%3A%2F%2F1... 1.331923e+09
9 http://t.co/o1Pd0WeV 1.331923e+09
10 direct 1.331923e+09
11 http://t.co/ND7SoPyo 1.331923e+09
12 direct 1.331923e+09
13 NaN NaN
14 direct 1.331923e+09
15 http://forum2.hkgolden.com/view.aspx?type=BW&m... 1.331923e+09
16 http://forum2.hkgolden.com/view.aspx?type=BW&m... 1.331923e+09
17 http://t.co/6Cx4ROLs 1.331923e+09
18 http://www.AwareMap.com/ 1.331923e+09
19 http://www.facebook.com/ 1.331923e+09
20 http://www.facebook.com/ 1.331923e+09
21 http://www.facebook.com/ 1.331923e+09
22 direct 1.331923e+09
23 http://www.facebook.com/l.php?u=http%3A%2F%2F1... 1.331923e+09
24 http://www.facebook.com/ 1.331923e+09
25 http://www.facebook.com/ 1.331923e+09
26 http://www.facebook.com/?ref=tn_tnmn 1.331923e+09
27 direct 1.331923e+09
28 direct 1.331923e+09
29 http://t.co/5xlp0B34 1.331923e+09
... ... ...
3530 http://www.facebook.com/l.php?u=http%3A%2F%2Fg... 1.331927e+09
3531 direct 1.331927e+09
3532 http://www.ncsha.org/ 1.331927e+09
3533 direct 1.331927e+09
3534 direct 1.331927e+09
3535 direct 1.331927e+09
3536 http://t.co/g1VKE8zS 1.331927e+09
3537 http://t.co/A8TJyibE 1.331927e+09
3538 direct 1.331927e+09
3539 direct 1.331927e+09
3540 http://www.facebook.com/l.php?u=http%3A%2F%2F1... 1.331927e+09
3541 direct 1.331927e+09
3542 http://www.facebook.com/l.php?u=http%3A%2F%2F1... 1.331927e+09
3543 NaN NaN
3544 direct 1.331927e+09
3545 direct 1.331927e+09
3546 direct 1.331927e+09
3547 direct 1.331927e+09
3548 https://twitter.com/fdarecalls/status/18069759... 1.331927e+09
3549 direct 1.331927e+09
3550 http://www.linkedin.com/home?trk=hb_tab_home_top 1.331927e+09
3551 http://plus.url.google.com/url?sa=z&n=13319268... 1.331927e+09
3552 direct 1.331927e+09
3553 http://www.shrewsbury-ma.gov/selco/ 1.331927e+09
3554 http://www.shrewsbury-ma.gov/selco/ 1.331927e+09
3555 direct 1.331927e+09
3556 http://www.facebook.com/l.php?u=http%3A%2F%2F1... 1.331927e+09
3557 http://www.AwareMap.com/ 1.331927e+09
3558 direct 1.331927e+09
3559 http://t.co/OEEEvwjU 1.331927e+09
tz u
0 America/New_York http://www.ncbi.nlm.nih.gov/pubmed/22415991
1 America/Denver http://www.monroecounty.gov/etc/911/rss.php
2 America/New_York http://boxer.senate.gov/en/press/releases/0316...
3 America/Sao_Paulo http://apod.nasa.gov/apod/ap120312.html
4 America/New_York http://www.shrewsbury-ma.gov/egov/gallery/1341...
5 America/New_York http://www.shrewsbury-ma.gov/egov/gallery/1341...
6 Europe/Warsaw http://www.nasa.gov/mission_pages/nustar/main/...
7 http://www.nasa.gov/mission_pages/nustar/main/...
8 http://www.nasa.gov/mission_pages/nustar/main/...
9 http://apod.nasa.gov/apod/ap120312.html
10 America/Los_Angeles https://www.nysdot.gov/rexdesign/design/commun...
11 America/New_York http://oversight.house.gov/wp-content/uploads/...
12 America/New_York https://www.nysdot.gov/rexdesign/design/commun...
13 NaN NaN
14 America/New_York http://toxtown.nlm.nih.gov/index.php
15 Asia/Hong_Kong http://www.ssd.noaa.gov/PS/TROP/TCFP/data/curr...
16 Asia/Hong_Kong http://www.usno.navy.mil/NOOC/nmfc-ph/RSS/jtwc...
17 America/New_York http://www.usda.gov/wps/portal/usda/usdahome?c...
18 America/Denver http://www.monroecounty.gov/etc/911/rss.php
19 Europe/Rome http://www.nasa.gov/mission_pages/nustar/main/...
20 Africa/Ceuta http://voyager.jpl.nasa.gov/imagesvideo/uranus...
21 America/New_York http://www.nasa.gov/mission_pages/nustar/main/...
22 America/New_York http://portal.hud.gov/hudportal/documents/hudd...
23 America/New_York http://www.tricare.mil/mybenefit/ProfileFilter...
24 Europe/Madrid http://www.nasa.gov/mission_pages/nustar/main/...
25 Asia/Kuala_Lumpur http://www.nasa.gov/mission_pages/nustar/main/...
26 Asia/Nicosia http://www.nasa.gov/mission_pages/nustar/main/...
27 America/Sao_Paulo http://apod.nasa.gov/apod/ap120312.html
28 https://www.nysdot.gov/rexdesign/design/commun...
29 http://www.ed.gov/news/media-advisories/us-dep...
... ... ...
3530 America/Los_Angeles http://www.nasa.gov/multimedia/imagegallery/im...
3531 http://www.nasa.gov/mission_pages/nustar/main/...
3532 America/New_York http://portal.hud.gov/hudportal/HUD?src=/press...
3533 America/New_York http://apod.nasa.gov/apod/
3534 America/Chicago https://www.nysdot.gov/rexdesign/design/commun...
3535 America/Chicago http://ntl.bts.gov/lib/44000/44300/44374/FHWA-...
3536 http://www.nasa.gov/mission_pages/hurricanes/a...
3537 America/Tegucigalpa http://apod.nasa.gov/apod/ap120312.html
3538 America/Los_Angeles http://healthypeople.gov/2020/connect/webinars...
3539 America/Los_Angeles http://www.federalreserve.gov/newsevents/press...
3540 America/Denver http://www.nasa.gov/mission_pages/nustar/main/...
3541 America/Los_Angeles http://www.federalreserve.gov/newsevents/press...
3542 America/Los_Angeles http://www.sba.gov/community/blogs/community-b...
3543 NaN NaN
3544 America/Chicago https://www.nysdot.gov/rexdesign/design/commun...
3545 America/Chicago https://www.nysdot.gov/rexdesign/design/commun...
3546 America/Los_Angeles http://healthypeople.gov/2020/connect/webinars...
3547 America/New_York http://www.epa.gov/otaq/regs/fuels/additive/e1...
3548 America/Chicago http://www.fda.gov/Safety/Recalls/ucm296326.htm
3549 Europe/Stockholm http://www.nasa.gov/mission_pages/WISE/main/in...
3550 America/New_York http://www.nlm.nih.gov/medlineplus/news/fullst...
3551 http://www.nasa.gov/mission_pages/nustar/main/...
3552 America/Chicago http://travel.state.gov/passport/passport_5535...
3553 America/New_York http://www.shrewsbury-ma.gov/egov/gallery/1341...
3554 America/New_York http://www.shrewsbury-ma.gov/egov/gallery/1341...
3555 America/New_York http://www.fda.gov/AdvisoryCommittees/Committe...
3556 America/Chicago http://www.okc.gov/PublicNotificationSystem/Fo...
3557 America/Denver http://www.monroecounty.gov/etc/911/rss.php
3558 America/Los_Angeles http://www.ahrq.gov/qual/qitoolkit/
3559 America/New_York http://herndon-va.gov/Content/public_safety/Pu...
[3560 rows x 18 columns]
'Mozilla/5.0 (Linux; U; Android 2.2.2; en-us; LG-P925/V10e Build/FRG83G) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
1 2 3 4 5 6 7 8
# dropna()函数可以去掉包含有NaN值得item # frame.a.drapna()就是提取frame表格里列表为a的那一列,去除掉NA值得那些行的值 # x.split(str) 通过指定分隔符str对字符串x进行切片,默认分隔符为空格,x.split(str)[0]意在取切完片的第一个值 # [x.split()[0] for x in frame.a.dropna()]就是提取frame表格里列表为a的那一列,去除掉NA值得那些行的值,并用split进行分割,并且最后保存分割后的第一个值,构成一个list # Series是Pandas包中的方法,构建Series对象,添加索引 results = Series([x.split()[0] for x in frame.a.dropna()]) # 打印出来看看,后边的乱七八糟的信息已经没有了 results[:5]
# 导入json包 import json # 创建变量并赋值,这里path是数据所在路径 path = 'ch02/usagov_bitly_data2012-03-16-1331923249.txt' # json.loads():以json格式读取数据,读取出来是key:value对,可以像字典一样查询 # for line in open(path):逐行遍历path文件中的数据 # [json.loads(line) for line in open(path)]:逐行遍历path文件中的数据,通过按照json格式读取,然后每一行的作为一个item组成list(就是外边那个方括号的作用) records = [json.loads(line) for line in open(path)]
# for rec in records:吧records这个list里边的item逐个取出,每次取出都用rec命名 # [rec['tz'] for rec in records]:把rec中key为‘tz’的value取出来,作为item构建list # 直接运行会报错,因为有的行里边是没有‘tz’这个key的 time_zones = [rec['tz'] for rec in records]
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-9-abb6a4fa53e3> in <module>()
2 # [rec['tz'] for rec in records]:把rec中key为‘tz’的value取出来,作为item构建list
3 # 直接运行会报错,因为有的行里边是没有‘tz’这个key的
----> 4 time_zones = [rec['tz'] for rec in records]
<ipython-input-9-abb6a4fa53e3> in <listcomp>(.0)
2 # [rec['tz'] for rec in records]:把rec中key为‘tz’的value取出来,作为item构建list
3 # 直接运行会报错,因为有的行里边是没有‘tz’这个key的
----> 4 time_zones = [rec['tz'] for rec in records]
KeyError: 'tz'
1 2 3
# 因此这一句在上一句的基础上,增加if 'tz' in rec,意为只把tz的rec中的value构成list # 因此time_zones的长度小于records time_zones = [rec['tz'] for rec in records if'tz'in rec]
# counts.items():把counts这个字典中的key和value成对取出 # [(count, tz) for tz, count in counts.items()]:把键值对以二元组的形式构成list [(count, tz) for tz, count in counts.items()]
<xsd:annotation> <xsd:documentation> Schema for Executable Process for WS-BPEL 2.0 OASIS Standard 11th April, 2007 </xsd:documentation> </xsd:annotation>
<xsd:elementname="process"type="tProcess"> <xsd:annotation> <xsd:documentation> This is the root element for a WS-BPEL 2.0 process. </xsd:documentation> </xsd:annotation> </xsd:element>
<xsd:complexTypename="tExtensibleElements"> <xsd:annotation> <xsd:documentation> This type is extended by other component types to allow elements and attributes from other namespaces to be added at the modeled places. </xsd:documentation> </xsd:annotation> <xsd:sequence> <xsd:elementref="documentation"minOccurs="0"maxOccurs="unbounded"/> <xsd:anynamespace="##other"processContents="lax"minOccurs="0"maxOccurs="unbounded"/> </xsd:sequence> <xsd:anyAttributenamespace="##other"processContents="lax"/> </xsd:complexType>
<xsd:groupname="activity"> <xsd:annotation> <xsd:documentation> All standard WS-BPEL 2.0 activities in alphabetical order. Basic activities and structured activities. Addtional constraints: - rethrow activity can be used ONLY within a fault handler (i.e. "catch" and "catchAll" element) - compensate or compensateScope activity can be used ONLY within a fault handler, a compensation handler or a termination handler </xsd:documentation> </xsd:annotation> <xsd:choice> <xsd:elementref="assign"/> <xsd:elementref="compensate"/> <xsd:elementref="compensateScope"/> <xsd:elementref="empty"/> <xsd:elementref="exit"/> <xsd:elementref="extensionActivity"/> <xsd:elementref="flow"/> <xsd:elementref="forEach"/> <xsd:elementref="if"/> <xsd:elementref="invoke"/> <xsd:elementref="pick"/> <xsd:elementref="receive"/> <xsd:elementref="repeatUntil"/> <xsd:elementref="reply"/> <xsd:elementref="rethrow"/> <xsd:elementref="scope"/> <xsd:elementref="sequence"/> <xsd:elementref="throw"/> <xsd:elementref="validate"/> <xsd:elementref="wait"/> <xsd:elementref="while"/> </xsd:choice> </xsd:group>
<xsd:elementname="catch"type="tCatch"> <xsd:annotation> <xsd:documentation> This element can contain all activities including the activities compensate, compensateScope and rethrow. </xsd:documentation> </xsd:annotation> </xsd:element>
<xsd:elementname="catchAll"type="tActivityContainer"> <xsd:annotation> <xsd:documentation> This element can contain all activities including the activities compensate, compensateScope and rethrow. </xsd:documentation> </xsd:annotation> </xsd:element>
<xsd:complexTypename="tEventHandlers"> <xsd:annotation> <xsd:documentation> XSD Authors: The child element onAlarm needs to be a Local Element Declaration, because there is another onAlarm element defined for the pick activity. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tExtensibleElements"> <xsd:sequence> <xsd:elementref="onEvent"minOccurs="0"maxOccurs="unbounded"/> <xsd:elementname="onAlarm"type="tOnAlarmEvent"minOccurs="0"maxOccurs="unbounded"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexTypename="tOnMsgCommon"> <xsd:annotation> <xsd:documentation> XSD Authors: The child element correlations needs to be a Local Element Declaration, because there is another correlations element defined for the invoke activity. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tExtensibleElements"> <xsd:sequence> <xsd:elementname="correlations"type="tCorrelations"minOccurs="0"/> <xsd:elementref="fromParts"minOccurs="0"/> </xsd:sequence> <xsd:attributename="partnerLink"type="xsd:NCName"use="required"/> <xsd:attributename="portType"type="xsd:QName"use="optional"/> <xsd:attributename="operation"type="xsd:NCName"use="required"/> <xsd:attributename="messageExchange"type="xsd:NCName"use="optional"/> <xsd:attributename="variable"type="BPELVariableName"use="optional"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexTypename="tCorrelations"> <xsd:annotation> <xsd:documentation> XSD Authors: The child element correlation needs to be a Local Element Declaration, because there is another correlation element defined for the invoke activity. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tExtensibleElements"> <xsd:sequence> <xsd:elementname="correlation"type="tCorrelation"minOccurs="1"maxOccurs="unbounded"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexTypename="tInvoke"> <xsd:annotation> <xsd:documentation> XSD Authors: The child element correlations needs to be a Local Element Declaration, because there is another correlations element defined for the non-invoke activities. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tActivity"> <xsd:sequence> <xsd:elementname="correlations"type="tCorrelationsWithPattern"minOccurs="0"/> <xsd:elementref="catch"minOccurs="0"maxOccurs="unbounded"/> <xsd:elementref="catchAll"minOccurs="0"/> <xsd:elementref="compensationHandler"minOccurs="0"/> <xsd:elementref="toParts"minOccurs="0"/> <xsd:elementref="fromParts"minOccurs="0"/> </xsd:sequence> <xsd:attributename="partnerLink"type="xsd:NCName"use="required"/> <xsd:attributename="portType"type="xsd:QName"use="optional"/> <xsd:attributename="operation"type="xsd:NCName"use="required"/> <xsd:attributename="inputVariable"type="BPELVariableName"use="optional"/> <xsd:attributename="outputVariable"type="BPELVariableName"use="optional"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexTypename="tCorrelationsWithPattern"> <xsd:annotation> <xsd:documentation> XSD Authors: The child element correlation needs to be a Local Element Declaration, because there is another correlation element defined for the non-invoke activities. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tExtensibleElements"> <xsd:sequence> <xsd:elementname="correlation"type="tCorrelationWithPattern"minOccurs="1"maxOccurs="unbounded"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexTypename="tPick"> <xsd:annotation> <xsd:documentation> XSD Authors: The child element onAlarm needs to be a Local Element Declaration, because there is another onAlarm element defined for event handlers. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tActivity"> <xsd:sequence> <xsd:elementref="onMessage"minOccurs="1"maxOccurs="unbounded"/> <xsd:elementname="onAlarm"type="tOnAlarmPick"minOccurs="0"maxOccurs="unbounded"/> </xsd:sequence> <xsd:attributename="createInstance"type="tBoolean"default="no"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexTypename="tReceive"> <xsd:annotation> <xsd:documentation> XSD Authors: The child element correlations needs to be a Local Element Declaration, because there is another correlations element defined for the invoke activity. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tActivity"> <xsd:sequence> <xsd:elementname="correlations"type="tCorrelations"minOccurs="0"/> <xsd:elementref="fromParts"minOccurs="0"/> </xsd:sequence> <xsd:attributename="partnerLink"type="xsd:NCName"use="required"/> <xsd:attributename="portType"type="xsd:QName"use="optional"/> <xsd:attributename="operation"type="xsd:NCName"use="required"/> <xsd:attributename="variable"type="BPELVariableName"use="optional"/> <xsd:attributename="createInstance"type="tBoolean"default="no"/> <xsd:attributename="messageExchange"type="xsd:NCName"use="optional"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexTypename="tReply"> <xsd:annotation> <xsd:documentation> XSD Authors: The child element correlations needs to be a Local Element Declaration, because there is another correlations element defined for the invoke activity. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tActivity"> <xsd:sequence> <xsd:elementname="correlations"type="tCorrelations"minOccurs="0"/> <xsd:elementref="toParts"minOccurs="0"/> </xsd:sequence> <xsd:attributename="partnerLink"type="xsd:NCName"use="required"/> <xsd:attributename="portType"type="xsd:QName"use="optional"/> <xsd:attributename="operation"type="xsd:NCName"use="required"/> <xsd:attributename="variable"type="BPELVariableName"use="optional"/> <xsd:attributename="faultName"type="xsd:QName"/> <xsd:attributename="messageExchange"type="xsd:NCName"use="optional"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexTypename="tScope"> <xsd:annotation> <xsd:documentation> There is no schema-level default for "exitOnStandardFault" at "scope". Because, it will inherit default from enclosing scope or process. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tActivity"> <xsd:sequence> <xsd:elementref="partnerLinks"minOccurs="0"/> <xsd:elementref="messageExchanges"minOccurs="0"/> <xsd:elementref="variables"minOccurs="0"/> <xsd:elementref="correlationSets"minOccurs="0"/> <xsd:elementref="faultHandlers"minOccurs="0"/> <xsd:elementref="compensationHandler"minOccurs="0"/> <xsd:elementref="terminationHandler"minOccurs="0"/> <xsd:elementref="eventHandlers"minOccurs="0"/> <xsd:groupref="activity"minOccurs="1"/> </xsd:sequence> <xsd:attributename="isolated"type="tBoolean"default="no"/> <xsd:attributename="exitOnStandardFault"type="tBoolean"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:elementname="compensationHandler"type="tActivityContainer"> <xsd:annotation> <xsd:documentation> This element can contain all activities including the activities compensate and compensateScope. </xsd:documentation> </xsd:annotation> </xsd:element>
实际上就是一个tActivityContainer
element:terminationHandler
1 2 3 4 5 6 7
<xsd:elementname="terminationHandler"type="tActivityContainer"> <xsd:annotation> <xsd:documentation> This element can contain all activities including the activities compensate and compensateScope. </xsd:documentation> </xsd:annotation> </xsd:element>
<xsd:complexTypename="tInvoke"> <xsd:annotation> <xsd:documentation> XSD Authors: The child element correlations needs to be a Local Element Declaration, because there is another correlations element defined for the non-invoke activities. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tActivity"> <xsd:sequence> <xsd:elementname="correlations"type="tCorrelationsWithPattern"minOccurs="0"/> <xsd:elementref="catch"minOccurs="0"maxOccurs="unbounded"/> <xsd:elementref="catchAll"minOccurs="0"/> <xsd:elementref="compensationHandler"minOccurs="0"/> <xsd:elementref="toParts"minOccurs="0"/> <xsd:elementref="fromParts"minOccurs="0"/> </xsd:sequence> <xsd:attributename="partnerLink"type="xsd:NCName"use="required"/> <xsd:attributename="portType"type="xsd:QName"use="optional"/> <xsd:attributename="operation"type="xsd:NCName"use="required"/> <xsd:attributename="inputVariable"type="BPELVariableName"use="optional"/> <xsd:attributename="outputVariable"type="BPELVariableName"use="optional"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexTypename="tCorrelationsWithPattern"> <xsd:annotation> <xsd:documentation> XSD Authors: The child element correlation needs to be a Local Element Declaration, because there is another correlation element defined for the non-invoke activities. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tExtensibleElements"> <xsd:sequence> <xsd:elementname="correlation"type="tCorrelationWithPattern"minOccurs="1"maxOccurs="unbounded"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexTypename="tPick"> <xsd:annotation> <xsd:documentation> XSD Authors: The child element onAlarm needs to be a Local Element Declaration, because there is another onAlarm element defined for event handlers. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tActivity"> <xsd:sequence> <xsd:elementref="onMessage"minOccurs="1"maxOccurs="unbounded"/> <xsd:elementname="onAlarm"type="tOnAlarmPick"minOccurs="0"maxOccurs="unbounded"/> </xsd:sequence> <xsd:attributename="createInstance"type="tBoolean"default="no"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexTypename="tReceive"> <xsd:annotation> <xsd:documentation> XSD Authors: The child element correlations needs to be a Local Element Declaration, because there is another correlations element defined for the invoke activity. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tActivity"> <xsd:sequence> <xsd:elementname="correlations"type="tCorrelations"minOccurs="0"/> <xsd:elementref="fromParts"minOccurs="0"/> </xsd:sequence> <xsd:attributename="partnerLink"type="xsd:NCName"use="required"/> <xsd:attributename="portType"type="xsd:QName"use="optional"/> <xsd:attributename="operation"type="xsd:NCName"use="required"/> <xsd:attributename="variable"type="BPELVariableName"use="optional"/> <xsd:attributename="createInstance"type="tBoolean"default="no"/> <xsd:attributename="messageExchange"type="xsd:NCName"use="optional"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexTypename="tReply"> <xsd:annotation> <xsd:documentation> XSD Authors: The child element correlations needs to be a Local Element Declaration, because there is another correlations element defined for the invoke activity. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tActivity"> <xsd:sequence> <xsd:elementname="correlations"type="tCorrelations"minOccurs="0"/> <xsd:elementref="toParts"minOccurs="0"/> </xsd:sequence> <xsd:attributename="partnerLink"type="xsd:NCName"use="required"/> <xsd:attributename="portType"type="xsd:QName"use="optional"/> <xsd:attributename="operation"type="xsd:NCName"use="required"/> <xsd:attributename="variable"type="BPELVariableName"use="optional"/> <xsd:attributename="faultName"type="xsd:QName"/> <xsd:attributename="messageExchange"type="xsd:NCName"use="optional"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:complexTypename="tScope"> <xsd:annotation> <xsd:documentation> There is no schema-level default for "exitOnStandardFault" at "scope". Because, it will inherit default from enclosing scope or process. </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:extensionbase="tActivity"> <xsd:sequence> <xsd:elementref="partnerLinks"minOccurs="0"/> <xsd:elementref="messageExchanges"minOccurs="0"/> <xsd:elementref="variables"minOccurs="0"/> <xsd:elementref="correlationSets"minOccurs="0"/> <xsd:elementref="faultHandlers"minOccurs="0"/> <xsd:elementref="compensationHandler"minOccurs="0"/> <xsd:elementref="terminationHandler"minOccurs="0"/> <xsd:elementref="eventHandlers"minOccurs="0"/> <xsd:groupref="activity"minOccurs="1"/> </xsd:sequence> <xsd:attributename="isolated"type="tBoolean"default="no"/> <xsd:attributename="exitOnStandardFault"type="tBoolean"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>
<xsd:elementname="compensationHandler"type="tActivityContainer"> <xsd:annotation> <xsd:documentation> This element can contain all activities including the activities compensate and compensateScope. </xsd:documentation> </xsd:annotation> </xsd:element>
实际上就是一个tActivityContainer
element:terminationHandler
1 2 3 4 5 6 7
<xsd:elementname="terminationHandler"type="tActivityContainer"> <xsd:annotation> <xsd:documentation> This element can contain all activities including the activities compensate and compensateScope. </xsd:documentation> </xsd:annotation> </xsd:element>