我正在处理一个csv文件(100行),其中包含以下数据。我想以csv/tab格式获得每个元素每个基因的计数
输入
Gene Element
---------- ----------
STBZIP1 G-box
STBZIP1 G-box
STBZIP1 MYC
STBZIP1 MYC
STBZIP1 MYC
STBZIP10 MYC
STBZIP10 MYC
STBZIP10 MYC
STBZIP10 G-box
STBZIP10 G-box
STBZIP10 G-box
STBZIP10 G-box
预期产出
Gene G-Box MYC
---------- ------- -----
STBZIP1 2 3
STBZIP10 4 3
有人能帮我在这方面想出一个bash脚本(或python)吗
更新
我正在尝试下面的方法,但暂时没有成功:|
import pandas as pd
df = pd.read_csv("Promoter_Element_Distribution.csv")
print (df)
df.groupby(['Gene', 'Element']).size().unstack(fill_value=0)
因为您还要求提供bash版本,所以这里使用了
awk
1。它是有注释的,而且输出的格式是“良好的”,所以代码有点大(大约20行没有注释)结果:
1由于Ed Morton
文件格式为(此处名为
input.csv
):这个
给你
相关问题 更多 >
编程相关推荐