【问题标题】:PCA analysis with python pandas with many columns使用具有多列的 python pandas 进行 PCA 分析
【发布时间】:2016-03-25 18:57:47
【问题描述】:

我有一个 .vcf 文件,其中

column1 = chrom
column2 = pos
column3 = ID
column4 = reference
column5 = Alt
column6 = qual
column7 = filter
column8 = info
column9 = format    
column 10 - 99 = 100 columns that have a number of either zero or one

我在文件中读到:

#!/usr/bin/env python
import pandas as pd
vcf=open('/Users/cmdb/Desktop/Lab6_GWAS/variants.vcf', 'r')

并且有这个不应该使用的

for line in vcf:
    fields=line.strip().split()
    A01=fields[9]
    A02=fields[10]
    A03=fields[11]

但是,这会花费太长时间,因为我想保存所有那些 1,以便稍后通过 Python 运行 PCA 分析。 PCA(主成分分析)。我想使用pandas,但不确定如何为这么多列做到这一点。

【问题讨论】:

    标签: python pandas pca


    【解决方案1】:

    pandas 没有实现 PCA 算法。

    请改用sklearn

    from sklearn.decomposition import PCA
    pca = PCA(n_components=5)
    pca.fit(df)
    

    并像这样访问组件:

    pca.components_ 
    

    【讨论】:

      猜你喜欢
      • 2013-04-07
      • 2012-11-20
      • 2013-03-28
      • 2017-12-24
      • 2016-01-12
      • 2017-12-29
      • 1970-01-01
      相关资源
      最近更新 更多