开发者社区> 问答> 正文

dataframe中如何创建包含每行最小值与最大值比例的列?

dataframe中如何创建包含每行最小值与最大值比例的列?

展开
收起
游客y244y7ln2rlpa 2021-12-05 20:31:47 359 0
1 条回答
写回答
取消 提交回答
  • df = pd.DataFrame(np.random.randint(1,100, 9).reshape(3, -1))
    print(df)
    # 方法1:axis=1表示行方向,
    min_by_max = df.apply(lambda x: np.min(x)/np.max(x), axis=1)
    
    # 方法2
    min_by_max = np.min(df, axis=1)/np.max(df, axis=1)
    
    min_by_max
    
    #>	    0   1   2
    	0  81  68  59
    	1  45  73  23
    	2  20  22  69
    	
    #>	0    0.728395
    	1    0.315068
    	2    0.289855
    	dtype: float64
    
    
    2021-12-05 22:22:58
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载