1. join( )
Python join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。
s1 = "-"
s2 = ""
seq = ("r", "u", "n", "o", "o", "b")
print (s1.join( seq ))
print (s2.join( seq ))
以上实例输出结果如下:
r-u-n-o-o-b
runoob
2. pandas.apply()
import numpy as np
import pandas as pd
f = lambda x: x.max()-x.min()
df = pd.DataFrame(np.random.randn(4,3),columns=list('bde'),index=['utah', 'ohio', 'texas', 'oregon'])
print(df)
t1 = df.apply(f)
print(t1)
t2 = df.apply(f, axis=1)
print(t2)
以上实例输出结果如下:
b d e
utah 1.106486 0.101113 -0.494279
ohio 0.955676 -1.889499 0.522151
texas 1.891144 -0.670588 0.106530
oregon -0.062372 0.991231 0.294464
b 1.953516
d 2.880730
e 1.016430
dtype: float64
utah 1.600766
ohio 2.845175
texas 2.561732
oregon 1.053603
dtype: float64
|