1. About the map function
>>> map(lambda x: x ** 2, [1, 2, 3, 4, 5]) # 使用 lambda 匿名函数
[1, 4, 9, 16, 25]
2.apply function
import pandas as pd
import numpy as np
matrix = [
[1,2,3],
[4,5,6],
[7,8,9]
]
df = pd.DataFrame(matrix, columns=list('xyz'), index=list('abc'))
df.apply(np.square)
df.apply(lambda x:np.square(x) if x.name=='x' else x)
Square the df x columns.
By default, axis = 0 means by column, axis = 1 means by row, such as
df.apply (lambda x: np.square (x) if x.name == 'b' else x, axis = 1)
3.drop () function
print(df.drop("a"))
print(df.drop("x",axis=1))