1.报错修改np.bool
—bool
H:\Anaconda3-2020.02\envs\parl\lib\site-packages\paddle\fluid\framework.py:541:
DeprecationWarning: np.bool
is a deprecated alias for the builtin bool
. To silence this warning, use bool
by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.bool_
here.

2.矩阵维度降维:action
输入状态和输出动作维度问题

3.1 方法一:for循环
records = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
result = []
for y in range(0, 4):
for x in range(0, 3):
if x == 0:
result.append([])
result[y].append(records[x + y * 3])
print(result)
3.2 第二种方法,numpy
1) 升维度
利用函数reshape或者是resize
使用reshape的时候需要注意reshape的结果不改变,因此适用于还要用到原数组的情况
使用resize会改变原数组,因此适用于一定需要修改后的结果为值的情况
import numpy as np
x = np.arange(20) # 生成数组
print(x)
result = x.reshape((4, 5)) # 将一维数组变成4行5列 原数组不会被修改或者覆盖
x.resize((2, 10)) # 覆盖原来的数据将新的结果给原来的数组
print(x)
2) 降维度
import numpy as np
arr = np.arange(10)
arr.resize((2, 5))
print(arr)
print(f"维度交换:\n{arr.swapaxes(1, 0)}")
print(f"C{arr.flatten('C')}") # 默认C 一行为主
print(f"\nF:{arr.flatten('F')}") # 以列为主
print(f"\nA:{arr.flatten('A')}") # 和行一样
print(f"\nK:{arr.flatten('K')}") # 和行一样
Original: https://blog.csdn.net/sinat_39620217/article/details/117842572
Author: 汀、
Title: 环境调试bug【一】
相关阅读
Title: python金融分析小知识(5)——如何查看DataFrame中的空值
Hello 大家好,我是一名新来的金融领域打工人,日常分享一些python知识,都是自己在学习生活中遇到的一些问题,分享给大家,希望对大家有一定的帮助!
在平时的数据分析当中,我们会经常遇到读入的数据存在空值的情况,面对庞大的数据量,我们不可能一个一个地去找空值,那么有没有比较方便的办法能够让我们快速找到DataFrame中的空值呢?答案是有的
让我举一个例子来说明:
[En]
Let me give you an example to illustrate:
首先我们构建一个包含空值的DataFrame,代码如下:
import pandas as pd
import numpy as np
df = pd.DataFrame({
"身高":[170,171,167,189,np.nan],
"体重":[65,66,68,np.nan,np.nan],
"视力":[4.0,3.8,5.0,np.nan,np.nan]
})
让我们打印一下这个DataFrame,得到结果:
身高 体重 视力
0 170.0 65.0 4.0
1 171.0 66.0 3.8
2 167.0 68.0 5.0
3 189.0 NaN NaN
4 NaN NaN NaN
我们可以很明显地看到空值NaN的存在,下面我们通过几种方式来查看空值:
1.通过bool值结果来查看空值
df.isnull()
# 或者
df.isna()
#或者
np.isnan(df)
这两行代码的结果是一样的,我们基本可以说 isnull()和isna()在使用中是等效的,得到的结果如下,其中False代表不是空值,True代表是空值:
身高 体重 视力
0 False False False
1 False False False
2 False False False
3 False True True
4 True True True
2.统计每一列空值的个数
df.isnull().sum()
# 或者
df.isna().sum()
# 或者
np.isnan(df).sum()
返回的结果是每列的空值个数,即身高列有一个空值,体重和视力列有两个空值:
[En]
The result returned is the number of null values for each column, that is, one null value for height column and two null values for weight and eyesight columns:
身高 1
体重 2
视力 2
dtype: int64
3.只统计一列的空值个数
如果您只想获取一列数据中的空值的数量,可以通过以下代码来实现:
[En]
If you only want to get the number of null values in a column of data, you can do this through the following code:
df['身高'].isnull().sum()
# 或者
df['身高'].isna().sum()
# 或者
np.isnan(df['身高']).sum()
返回结果如下,即Height列为空值:
[En]
The returned result is as follows, that is, the height column has a null value:
4.查看某列含有空值所在的整行
df[df['体重'].isnull()]
# 或者
df[df['体重'].isna()]
#或者
df[np.isnan(df['体重'])]
打印结果如下:
身高 体重 视力
3 189.0 NaN NaN
4 NaN NaN NaN
5.查看整个DataFrame中有空值的行
df[df.isnull().any(axis=1)] ##axis=1代表水平方向,axis=0代表竖向
# 或者
df[df.isna().any(axis=1)]
#或者
df[np.isnan(df).any(axis=1)]
打印结果如下:
身高 体重 视力
3 189.0 NaN NaN
4 NaN NaN NaN
总结:在查看空值的时候有三种方法可以实现也就是isnull()、isna()以及np.isnan(),这三种方法可以说是等效的,大家可以结合不同的目的来选取自己喜欢的一种来使用就行!
今天的文章就到这里吧!
[En]
That’s all for today’s article!
Original: https://blog.csdn.net/qq_41281698/article/details/124570002
Author: 君子以自强不息python
Title: python金融分析小知识(5)——如何查看DataFrame中的空值
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/324122/
转载文章受原作者版权保护。转载请注明原作者出处!