python:분리 값 작업 삭제(행동 별 데이터)

2243 단어 python분리 값
여러 줄 문자열 이 있 는 json 파일 의 분리 값 을 삭제 합 니 다.

def processHold(eachsubject,directory,newfile):
	filename = 'CMUDataCol/Hold/subject{0}.json'.format(eachsubject) #    
	
	with open(filename, 'r') as f: 
		for jsonstr in f.readlines(): #        
		#               ,                  
		#       ,       
			data = json.loads(jsonstr)
			
			#      
			a = numpy.array(data) 
			q1 = numpy.percentile(a, 25)  
			q3 = numpy.percentile(a, 75)  
			iqr = q3 - q1
			
			#      
			i = 0 
			for item in zip(data): 
				#          i+1
				if item <= q3 + (1.5*iqr) and item >= q1 - (1.5*iqr):   
					i = i + 1  
					
			if i == 10: 
			#        json     data 10   (        ,     ,   !)  
				HoldTime = data
				with open(newfile, 'a') as f: #            
					json.dump(HoldTime, f) 
					f.write('
')
보충 지식:dataframe 분리 값 처리
분리 값:데이터 의 주요 부분 에서 멀리 떨 어 진 샘플(최대 값 또는 극소 값)
처리 방법:
삭제:분리 샘플 직접 삭제
샘플 채 우기:box-plot 를 사용 하여 변수의 수치 상하 계 를 정의 하고 이상 계 는 최대 값 을 채 우 며 하계 로 최소 값 을 채 웁 니 다.

#          
df['average_price'].hist()
plt.show()
df[['average_price']].boxplot()
plt.show()

#                  
def boxplot_fill(col):
 #   iqr:                   
 iqr = col.quantile(0.75)-col.quantile(0.25)
 #   iqr         
 u_th = col.quantile(0.75) + 1.5*iqr #   
 l_th = col.quantile(0.25) - 1.5*iqr #   
 #       :               ,           。
 def box_trans(x):
  if x > u_th:
   return u_th
  elif x < l_th:
   return l_th
  else:
   return x
 return col.map(box_trans)
#       
boxplot_fill(df['average_price']).hist()
#     
df['average_price'] = boxplot_fill(df['average_price'])
plt.show()
이상 의 python:분리 값 작업(모든 행위 와 같은 데이터)을 삭제 하 는 것 은 바로 작은 편집 이 여러분 에 게 공유 하 는 모든 내용 입 니 다.참고 하 시기 바 랍 니 다.여러분 들 이 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기