当前位置:网站首页>pd.melt() vs reshape2::melt()
pd.melt() vs reshape2::melt()
2022-07-25 18:20:00 【qq_ forty-five million seven hundred and fifty-nine thousand tw】
Sometimes DataFrame Multiple columns of data in the variable layer, two columns and three columns of data for drawing , This operation is called melt, stay R and python It is implemented in , Record the following
R Merge the two columns into one column
df=data.frame(v1=c(1,2,3),v2=c("2","2","100"))
df
reshape2::melt(df,id.vars=NULL)
give the result as follows 
python Merge the two columns into one column

R Merge multiple columns of data into three columns
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
give the result as follows 
python Merge multiple columns of data into three columns
mem_df=pd.read_csv("./mem_df.csv",index_col=0)
mem_df
mem_final=pd.melt(mem_df,id_vars="samplesize")
give the result as follows 

边栏推荐
猜你喜欢

BiSeNet v1

越来越成熟的Rust,都应用了哪些场景呢?

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

乐观锁解析

这是一张机器&深度学习代码速查表

How to judge the performance of static code quality analysis tools? These five factors must be considered

超全Mavan标签详解

Landmark buildings around the world

"Digital security" alert NFT's seven Scams

用GaussDB(for Redis)存画像,推荐业务轻松降本60%
随机推荐
RTC 性能自动化工具在内存优化场景下的实践
Optimistic lock pessimistic lock applicable scenario
对角化、A的幂
Problems faced by cloud XR and main application scenarios of cloud XR
Talking about Devops monitoring, how does the team choose monitoring tools?
喜讯!瑞云科技被授予“海上扬帆”5G融合应用专委会成员单位
Recommend a qinheng Bluetooth reference blog
The new version of 3dcat v2.1.3 has been released. You can't miss these three function updates!
NC68 跳台阶
php内存管理机制与垃圾回收机制
柔性电流探头选型指南
云流化和云桌面有什么关系
超全Mavan标签详解
越来越成熟的Rust,都应用了哪些场景呢?
Use of join function in MATLAB
Number two 2010 real test site
Keil5 “Loading PDSC Debug Description Failed for STMicroelectronics STM32Hxxxxxxx”解决办法
Tkinter GUI address book management system
11.1-CM24 最近公共祖先
GAN的详细介绍及其应用(全面且完整)