Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中R函数的应用_Python_R_Pandas - Fatal编程技术网

python中R函数的应用

python中R函数的应用,python,r,pandas,Python,R,Pandas,我在R中有一个有效的代码。但我想在python中重新实现它。我使用R来使用apply函数来计算次要等位基因频率。有人能告诉我这样的代码在python中会是什么样子吗?我使用pandas读取python中的数据 ##R-code ###Reading file var_freq <- read_delim("./cichlid_subset.frq", delim = "\t", col_names = c

我在R中有一个有效的代码。但我想在python中重新实现它。我使用R来使用apply函数来计算次要等位基因频率。有人能告诉我这样的代码在python中会是什么样子吗?我使用pandas读取python中的数据

##R-code
###Reading file
var_freq <- read_delim("./cichlid_subset.frq", delim = "\t",
                       col_names = c("chr", "pos", "nalleles", "nchr", "a1", "a2"), skip = 1)

# find minor allele frequency
var_freq$maf <- var_freq %>% select(a1, a2) %>% apply(1, function(z) min(z))

如有见解,将不胜感激。

使用:

#读取文件
colnames=[“chr”、“pos”、“nallles”、“nchr”、“a1”、“a2”]
var\u freq=pd.read\u csv('./cichlid\u subset.frq',sep='\t',header=None,skiprows=1,names=colnames)
#获取MAF
变量频率['maf']=变量频率[['a1','a2']].min(轴=1)
使用:

#读取文件
colnames=[“chr”、“pos”、“nallles”、“nchr”、“a1”、“a2”]
var\u freq=pd.read\u csv('./cichlid\u subset.frq',sep='\t',header=None,skiprows=1,names=colnames)
#获取MAF
变量频率['maf']=变量频率[['a1','a2']].min(轴=1)

这是否回答了您的问题?不,我想看看如何用python做同样的事情。这能回答你的问题吗?不,我想看看我如何用python做同样的事情。谢谢,它成功了:)谢谢,它成功了:)
###Python code
###Reading file
var_freq = pd.read_csv("./cichlid_subset.frq",sep='\t',header=None)
column_indices = [0,1,2,3,4,5]
new_names = ["chr", "pos", "nalleles", "nchr", "a1", "a2"]
old_names = df_snv_gnomad.columns[column_indices]

###Finding minor allele frequency