[英]How to convert a pandas dataframe column to an image array i.e. a numpy array with shape (n,n) in Python?
[英]How to create a DataFrame in which last column (i.e. fifth column) will be the addition of first four column
前四列是在一定范围内随机生成的。 第五列包含前四列的添加。 第五列的值不应超过 10。
不知道我是否理解得很好:
import numpy as np
import pandas as pd
A=np.random.randint(0.5,5,10)
B=np.random.randint(.50,10,10)
C=np.random.randint(0.8,8,10)
D=np.random.randint(0.1,2,10)
E=A+B+C+D
df={'A':A,'B':B, 'C':C,'E':E}
df= pd.DataFrame(df)
df['E'].values[df['E'] > 10] = 0 # if E bigger than 10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.