Jupyter에서 처리하려고하는 데이터 프레임이 있습니다. 이 데이터 프레임은 원래 공백이있는 NaN
으로 채워지지만, 이후로는 'Null'문자열로 바꾸기로 결정했습니다 (이후 NaN
을 무시하는 문제가 있었기 때문에). 없는 모든 요소가 NaN
(또는 그 이후의 '널') 내가 먹을 수 그 곳 필터링 할 경우Python에서 배열의 조건과 일치하는 모든 요소 검색
다음 코드는 원본 파일의 샘플입니다 mydata.txt
##IGNORE THIS LINE
group2,"BLA","BLE","BLI","BLO","BLU","TAT","TET","TOT","TUT"
group0,"BLA","BLE","BLI","BLO","BLU"
group3,"BLA","BLE","BLI"
아이디어는 배열을 구축하는 것입니다 그밖에.
import rpy2.ipython
import rpy2.robjects as robjects
import pandas as pd
import numpy
import re #python for regex
%load_ext rpy2.ipython
%R
path='C:/MyPath/'
allgroups=pd.read_csv(path+'mydata.txt',sep=",",skiprows=1,header=None,index_col=0)
allgroups=allgroups.fillna("Null")
def groupdat(groupname):
#Cleans group
precleaned=numpy.array(allgroups.loc[[groupname]])
# matching = [s for s in precleaned if s != "Null" ] #I tried this
matching=filter(lambda elem: elem != "Null",precleaned) #I also tried this.
print(matching)
return
groupdat('group0')
수율 위의 오류가 댓글을 달았 모두 matching
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
.
precleaned
의 출력은 인쇄 allgroups.loc[[groupname]]
[['BLA' 'BLE' 'BLI' 'BLO' 'BLU' 'Null' 'Null' 'Null' 'Null']]
이다 I 모든 피드백을 이해할
1 2 3 4 5 6 7 8 9
0
group0 BLA BLE BLI BLO BLU Null Null Null Null
[1 rows x 9 columns]
준다.
귀하의 제안은''[[ 'BLA' 'BLE' 'BLO' 'BLO' 'BLU' 'Null' 'Null' 'Null']''을 산출합니다. 너비가 너무 많으면 내가 뭘 잘못하고 있니? – Sosi
@ Jean-FrançoisFabre 도움을 주셔서 대단히 감사합니다. 그 프린트의 출력물을 원래 게시물에 추가했습니다. – Sosi
@ Jean-FrançoisFabre 걱정하지 마세요, 정말 감사드립니다. 나는 원래 게시물에 샘플을 추가했습니다. 다시 한번 감사드립니다 – Sosi