1. np.size:Numpy数组中元素个数
例:
import numpy as np
Z = np.zeros([10,10])
print('Z.size = {}'.format(Z.size))
## 输出 : Z.size = 100
Z.size = 10 * 10
2. np.itemsize:Numpy数组中每个元素所占 字节数
例:
import numpy as np
Z = np.zeros([10,10])
print('Z.itemsize = {}'.format(Z.itemsize))
## 输出 : Z.itemsize = 8
Z.itemsize = 8 原因解释:
- 进入调试状态查看Z的类型
- 由此我们可知np.zeros最开始默认未np.float64类型 我们float64占8个字节
- 拓展尝试:
- 将类型改为np.int32类型, 我们知道在32位机器上,int占4个字节。
import numpy as np
Z = np.zeros([10,10], dtype = np.int32)
print('Z.itemsize = {}'.format(Z.itemsize))
## 输出 : Z.itemsize = 4
- 将类型改为np.int64类型,我们知道在64位机器上,int占8个字节
import numpy as np
Z = np.zeros([10,10], dtype = np.int64)
print('Z.itemsize = {}'.format(Z.itemsize))
## 输出 : Z.itemsize = 8
3.np.size * np.itemsize:Numpy数组所占总内存空间字节数

Original: https://blog.csdn.net/m0_56316007/article/details/125715994
Author: 青_丘
Title: 一文读懂np.size、np.itemsize、np.size * np.itemsize
相关阅读
Title: 【Python 04】数据清洗:fillna()处理数据行中的缺失/异常值
图片一
图片二
对比图片二与图片一目的是:使各个 INDEX 后面6列数据等于其不为空值(not nan)且不为”.”的值。
那么可能会有几种方法来处理它,其中之一是:
[En]
Then there will probably be several ways to deal with it, one of which is:
把不同的 INDEX 里的第一条中的”.”和空值全部换成其下面的数据。
所以就会用到pandas里的 fillna() 或者 bfill() or ffill() 函数来处理。
import numpy as np
import pandas as pd
df = pd.read_excel(r"C:\xxxx\xxxx\xxxx\test list.xlsx")
图片三
df=df.replace('.',np.NAN)
df=df.bfill()
df=df.groupby('INDEX').first()
一、用空值替换掉”.”
二、用bfill向上填充
三、按INDEX 分组后取第一条数据
OK了,这样的话达到了我们预期目标啦~
我们来看看这题目所涉及的知识点 knowledge point 吧~
Pandas.DataFrame.fillna
Pandas 官方文档:
填充”空值”用的是这个特别的函数方式。
参数(因素)包括:
DataFrame.fillna(value=None, method=None, axis=None, inplace=False, limit=None, downcast=None)
- value: scalar, dict, Series, or DataFrame
支持的数据类型:scalar(标量), dict, Series, or DataFrame
Value to use to fill holes (e.g. 0), alternately a dict/Series/DataFrame of values specifying which value to use for each index (for a Series) or column (for a DataFrame). Values not in the dict/Series/DataFrame will not be filled. This value cannot be a list.
value 是用于填充的空值的值。
* method: {‘backfill’, ‘bfill’, ‘pad’, ‘ffill’, None}, default None
Method to use for filling holes in reindexed Series pad / ffill: propagate last valid observation forward to next valid backfill / bfill: use next valid observation to fill gap.
method参数:改变替代值的方式,当为’ffill’,表示用前面的值填充,当’bfill’表示用后面的值填充。
* axis: {0 or ‘index’, 1 or ‘columns’}
Axis along which to fill missing values.
axis参数默认为0,即沿着行填充,为1则沿着列填充
* inplace: bool, default False
If True, fill in-place. Note: this will modify any other views on this object (e.g., a no-copy slice for a column in a DataFrame).
传入inplace参数:是否在原来的数据上操作,默认为False,表示重新拷贝了一份数据,然后在拷贝的数据上操作。
* limit: int, default None
If method is specified, this is the maximum number of consecutive NaN values to forward/backward fill. In other words, if there is a gap with more than this number of consecutive NaNs, it will only be partially filled. If method is not specified, this is the maximum number of entries along the entire axis where NaNs will be filled. Must be greater than 0 if not None.
传入limit=” “限制填充个数
* downcast: dict, default is None
A dict of item->dtype of what to downcast if possible, or the string ‘infer’ which will try to downcast to an appropriate equal type (e.g. float64 to int64 if possible).
Original: https://blog.csdn.net/eason_nnn/article/details/123233093
Author: Eason DayDayUp
Title: 【Python 04】数据清洗:fillna()处理数据行中的缺失/异常值
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/321930/
转载文章受原作者版权保护。转载请注明原作者出处!