函数 | 含义 |
---|---|
dropna(axis, how) | 删除整行或整列(axis是按照啥方向, how是删的条件,这俩都是可选的) |
d.fillna(num) | 用num来替代其中的NaN |
d.isnull() | 返回一个bool matrix,NaN表示为True |
np.any(d.isnull()) == True | 判断d中有没有NaN |
axis挺迷的:
知乎的
import pandas as pd
import numpy as np
d = pd.DataFrame(np.linspace(2, 17, 16).reshape(4, 4), ['a', 'b', 'c', 'd'], ['A', 2, 3, 4])
d.loc['b', 3] = np.nan
d.loc['c', 2] = np.nan
print(type(d)) #
print(d)
print(d.dropna()) #
print(d.dropna(axis=1))
print(d.dropna(how='all'))
import pandas as pd
import numpy as np
d = pd.DataFrame(np.linspace(2, 17, 16).reshape(4, 4), ['a', 'b', 'c', 'd'], ['A', 2, 3, 4])
d.loc['b', 3] = np.nan
d.loc['c', 2] = np.nan
print(type(d)) #
print(d)
print(d.fillna(-1))
import pandas as pd
import numpy as np
d = pd.DataFrame(np.linspace(2, 17, 16).reshape(4, 4), ['a', 'b', 'c', 'd'], ['A', 2, 3, 4])
d.loc['b', 3] = np.nan
d.loc['c', 2] = np.nan
print(type(d)) #
print(d)
print(d.isnull())
import pandas as pd
import numpy as np
d = pd.DataFrame(np.linspace(2, 17, 16).reshape(4, 4), ['a', 'b', 'c', 'd'], ['A', 2, 3, 4])
d.loc['b', 3] = np.nan
d.loc['c', 2] = np.nan
print(type(d)) #
print(d)
print(np.any(d.isnull()) == True)