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

边栏推荐
- Chapter 5 Basic Scripting: Shell Variables
- 为什么数字化未来取决于3D实时渲染
- Keil5 "loading PDSC debug description failed for STMicroelectronics stm32hxxxxxxx" solution
- Use of C language cjson Library
- Related operations of binary tree
- C语言 libcurl交叉编译
- Boomi won the "best CEO in diversity" and the "best company in career growth" and ranked among the top 50 in the large company category
- Tkinter GUI address book management system
- Why the future of digitalization depends on 3D real-time rendering
- srec_cat 常用参数的使用
猜你喜欢

Construction of Huffman tree

"Digital security" alert NFT's seven Scams

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

"Jargon" | what kind of experience is it to efficiently deliver games with Devops?

Drawing PDF form (II) drawing excel form style in PDF through iText, setting Chinese font, watermark, logo, header and page number

Tkinter GUI address book management system

Li Kai: the interesting and cutting-edge audio and video industry has always attracted me

What scenarios have rust, which is becoming more and more mature, applied?

408 Chapter 2 linear table

Pan domain name configuration method
随机推荐
Linux启动mysql报错
Taishan Office Technology Lecture: conversion relations of inch, centimeter, pound, pika, Ti, line, word line and pixel
Drawing PDF form (II) drawing excel form style in PDF through iText, setting Chinese font, watermark, logo, header and page number
"Digital security" alert NFT's seven Scams
SDLC 软件开发生命周期及模型
Tkinter GUI address book management system
专访即构科技李凯:音视频的有趣、行业前沿一直吸引着我
Kendryte K210 在freertos上的lcd屏幕的使用
STM8S003F3 内部flash调试
MATLAB中join函数使用
Number two 2010 real test site
Oracle import error: imp-00038: unable to convert to environment character set handle
Pan domain name configuration method
What scenarios have rust, which is becoming more and more mature, applied?
Stm32f105rbt6 internal flash debugging
[MySQL]数据库中的索引为什么是用B+树来实现? 哈希表/红黑树/B树是否可行呢?
Oracle使用impdp导入报错:ORA-39001: 参数值无效 ORA-39000: 转储文件说明错误 ORA-39088: 文件名不能包含路径说明
虚拟偶像代言产品出问题谁负责?
Why is the index in [mysql] database implemented by b+ tree? Is hash table / red black tree /b tree feasible?
Redis source code and design analysis -- 16. AOF persistence mechanism