Is there anyway to copy the data from a single column in a Python pandas dataframe into a string or list for further processing? -


i trying iterate on python pandas created dataframe column column. while easy python print out whole column, cannot work out how turn column of data list or string can use data contains (in case, concatenating data , copying fasta file). code below. suggestions appreciated.

import sys import string import shlex import numpy np import pandas pd snp_df = pd.read_csv('snps.txt',sep='\t',index_col = none ,header = none, nrows = 101)   output = open('100 snps.fa','a')  i=1 in snp_df[i]:     data = snp_df[i]     data = shlex.shlex(data, posix = true)     data.whitespace += "\n"     data.whitespace_split = true     data = list(data)     j in data:         if j == 0:             output.write(("\n>%s\n")%(str(data(j))))         else:             output.write(data(j)) 

here first few lines of data file: position ref ar_dm1005 ar_dm1015 ar_dm1050 ar_dm1056 ar_dm1088 ar_kb635 ar_kb652 ar_kb754 ar_kb819 ar_kb820 ar_kb827 ar_kb945 ar_msh126 ar_msh51 pp_bda1134-13 pp_bda1137-10 pp_dm1038 pp_dm1049 pp_dm1054 pp_dm1065 pp_dm1081 pp_dm1084 pp_jr83 st_jr138 st_jr158 st_jr209 st_jr72 st_jr84 st_jr91 st_msh177 st_msh217 ch_jr198 ch_jr20 ch_jr272 ch_jr356 ch_jr377 ch_kb888 ch_msh202 tl_ma1959 tl_msh130 tl_sci12-2 tl_spe123_2-3 tl_spe123_5-1 tl_spe123_6-3 tl_spe123_7-1 tl_spe123_8-1 cu_spe123_1-2 cu_spe123_4-1 dmir_sp138
55 c t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t c
380 g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g
391 g a
402 g g g g g g g
422 c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c a
564 g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g

just use numpy! can convert series (1 column dataframe) 1d numpy array easily!

import numpy np in snp_df:     data = snp_df[i]     data = np.array(data)     j in data:         if j == 0:             output.write(("\n>%s\n")%(str(data(j))))         else:             output.write(data(j)) 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -