|
发表于 2021-8-6 23:17:38
|
显示全部楼层
这个'na',还是'nan',倒不是关键。关键是,若要进行运算,进行分组统计的时候,要注意 缺失值的类型和行为。
另外,我的numpy是1.17。
- scores = np.loadtxt('testdata.csv', dtype=np.str, delimiter=',', skiprows=1)
- scores
- array([['1', 'alice', '88'],
- ['2', 'bill', ''],
- ['3', 'cat', ''],
- ['4', 'david', '100']], dtype='<U5')
- np.NAN
- nan
- scores[scores==''] = np.NAN
- scores
- array([['1', 'alice', '88'],
- ['2', 'bill', 'nan'],
- ['3', 'cat', 'nan'],
- ['4', 'david', '100']], dtype='<U5')
- type(scores[2][2])
- numpy.str_
- scores[2][2] is np.NAN
- False
- np.__version__
- '1.17.1'
复制代码 |
|