当前位置:网站首页>pd.melt() vs reshape2::melt()
pd.melt() vs reshape2::melt()
2022-07-25 18:15:00 【qq_45759229】
有的时候将DataFrame中的多列数据变层两列和三列数据进行画图,这种操作称为melt, 在R和python中都有实现,记录如下
R将两列合并成一列
df=data.frame(v1=c(1,2,3),v2=c("2","2","100"))
df
reshape2::melt(df,id.vars=NULL)
结果如下
python将两列合并成一列

R将多列数据合并成三列
samplesize=c(1000,2000,5000,10000,20000,40000,50000,100000,300000,500000,1000000,1300000)
methods=c("DESC","DESC_GPU","DESC_multicpu","scVI","scVI_GPU","scVI_multicpu","Seurat3.0")
f_mem=function(x){
t1= x/100000
t2 =x/110000
t3= x/200000
t4= x/140000
t2 =x/500000
t5 =x/400000
t6= x/90000
t7= x/20000
mem =data.frame(samplesize=samplesize,t1=t1,t2=t2,t3=t3,t4=t4,t5=t5,t6=t6,t7=t7)
colnames(mem)=c("samplesize",methods)
return(mem)
}
mem_df =f_mem(samplesize)
write.csv(mem_df,file="./mem_df.csv")
mem_df
mem_final=reshape2::melt(mem_df,id.var="samplesize")
mem_final
结果如下
python将多列数据合并成三列
mem_df=pd.read_csv("./mem_df.csv",index_col=0)
mem_df
mem_final=pd.melt(mem_df,id_vars="samplesize")
结果如下

边栏推荐
- ORB_SLAM3复现——上篇
- MySQL 索引优化全攻略
- Why the future of digitalization depends on 3D real-time rendering
- 二叉树的相关操作
- MySQL lost the previous 0 after the decimal number type select
- c语言---25 扫雷游戏
- List转换问题
- Ch582 ble 5.0 uses Le coded broadcast and connection
- The new version of 3dcat v2.1.3 has been released. You can't miss these three function updates!
- Imx6 rtl8189ftv migration
猜你喜欢

Redis source code and design analysis -- 16. AOF persistence mechanism

云流化和云桌面有什么关系

Construction of Huffman tree

LeetCode 101. 对称二叉树 && 100. 相同的树 && 572. 另一棵树的子树

Kendryte K210 在freertos上的lcd屏幕的使用

Thales launches solutions to help SAP customers control cloud data

使用sqldeveloper连接mysql

Pan domain name configuration method

How to read a Book

为什么数字化未来取决于3D实时渲染
随机推荐
What scenarios have rust, which is becoming more and more mature, applied?
Mock service Moco series (II) - JSON format, file file, header, cookie, solving Chinese garbled code
Oracle导入出错:IMP-00038: 无法转换为环境字符集句柄
Keil5 “Loading PDSC Debug Description Failed for STMicroelectronics STM32Hxxxxxxx”解决办法
List转换问题
Today's sleep quality record is 84 points
UnitTest框架应用
更新|3DCAT实时云渲染 v2.1.2版本全新发布
MySQL lost the previous 0 after the decimal number type select
TESTNG中的并发测试invocationCount, threadPoolSize, timeOut的使用
Recommend a qinheng Bluetooth reference blog
Recognized by international authorities! Oceanbase was selected into the Forrester translational data platform report
Introduction to cloud XR and development opportunities of cloud XR in 5g Era
Mysql database common commands
NC15 求二叉树的层序遍历
实时云渲染有哪些优势
Postman get started quickly
Ch582 ble 5.0 uses Le coded broadcast and connection
Chapter 5 Basic Scripting: Shell Variables
List conversion problem