当前位置:网站首页>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")
结果如下

边栏推荐
猜你喜欢

Ch582 ble 5.0 uses Le coded broadcast and connection

Construction of Huffman tree

关于云XR介绍,以及5G时代云化XR的发展机遇

二叉树的相关操作

更新|3DCAT实时云渲染 v2.1.2版本全新发布

408 Chapter 2 linear table

Drawing PDF tables (I) drawing excel table styles in PDF and downloading them through iText (supporting Chinese fonts)

"Digital security" alert NFT's seven Scams

Talking about Devops monitoring, how does the team choose monitoring tools?

如何将exe文件添加到开机启动
随机推荐
Is there any inconspicuous but profitable sideline?
推荐一个沁恒的蓝牙的参考博客
Keil5 “Loading PDSC Debug Description Failed for STMicroelectronics STM32Hxxxxxxx”解决办法
Recognized by international authorities! Oceanbase was selected into the Forrester translational data platform report
基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现
1---电子实物认知
实时云渲染有哪些优势
How to judge the performance of static code quality analysis tools? These five factors must be considered
C语言 整数与字符串的相互转换
Mysql database common commands
Postman get started quickly
JZ32 从上往下打印二叉树
如何选择数字孪生可视化平台
Polynomial addition
结合GHS MULTI使用瑞萨E1仿真器实现对瑞萨RH850单片机的仿真调试
Error when starting MySQL on Linux
C语言 libcurl交叉编译
Basic knowledge of documents
Talking about Devops monitoring, how does the team choose monitoring tools?
nodejs 简单例子程序之express