게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
파이썬 고수님들 도와주세요.. csv작성문제
게시물ID : programmer_20952짧은주소 복사하기
작성자 : 내가뭘하던
추천 : 0
조회수 : 484회
댓글수 : 3개
등록시간 : 2017/07/05 17:11:00
2
2
2
2
가 적혀있는 face.txt파일에서 줄,합계,평균,표준편차,중앙값,최빈값,최소값,최대값을 찾아내서 빈 book.txt파일에 옮겨적는 프로그램을 작성중입니다.
infile = open("C:/Users/????/Desktop/face.txt", "r")
outfile = open("C:/Users/????/Desktop/book.txt", "w")

total1 =0
count1 =0

line = infile.readline()
while line !="":
    value = float(line)
    total1 = total1 + value
    count1 = count1 + 1
    line = infile.readline()
col1 = 1    
avg1 = total1 / count
sum1 = total1 / 4
std1 = 
med1 = 
mod1 = 
min1 = 
max1 = 
outfile.write("Column,Sum,Mean,STD,Median,Mode,Min,Max\n")
outfile.write("%1.0f" % col1)
outfile.write(",")
outfile.write("%1.0f" % total1)
outfile.write(",")
outfile.write("%1.0f" % sum1)
outfile.write(",")
outfile.write("%1.0f" % std1)
outfile.write(",")
outfile.write("%1.0f" % med1)
outfile.write(",")
outfile.write("%1.0f" % mod1)
outfile.write(",")
outfile.write("%1.0f" % min1)
outfile.write(",")
outfile.write("%1.0f" % max1)

infile.close()
outfile.close()

그러면 원하는 아웃풋은
Column,Sum,Mean,STD,Median,Mode,Min,Max
1, 8, 2, 0, 2, 2, 2, 2 
가 되야합니다.
사실 face.txt 를 2,2,2,2 로 저장하고싶었는데 쉼표가 들어가면 어떻게 짜야하는지 모르겠습니다...
그래서 위아래로 적었는데 쉼표를 적어넣은 값을 알아내는 방법을 알고 싶습니다.
두번째로 모듈을 사용하지않고 표준편차라던지 중앙값 같은 복잡한 식을 쓸순 없는것 같습니다.
중간중간에 기본모듈로 계산할수 있는 방법이 있을까요?

몇일을 붙잡았는데 결국엔 해결책을 못찾아서 이곳에 도움을 요청해봅니다 ㅠㅠ
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호