--------------------원형그래프---------------------
import matplotlib.pyplot as plt
blood = [1203, 1102, 308, 1697]
label = ['A', 'B', 'AB', 'O']
color = ['darkcyan', 'goldenrod', 'darkkhaki', 'seagreen']
plt.title('Blood Type')
plt.axis('equal')
plt.pie(blood, labels = label, autopct = '%.1f%%', colors = color,
explode=(0, 0, 0.2, 0))
plt.legend()
plt.show()
-------------------서울시 SNS 이용 행동 및 인식 통계---------------------
#CSV 파일을 읽고 쓰기위해서 import해준다.
import csv
#sns파일을 읽기형식으로 가져와서 file 변수에 열어준다. encoding 이란 파일 인식을 위해 써주었다.
file = open("sns.csv", 'r', encoding = 'utf-8')
# csv 파일 불러오기. 'r'모드가 기본값
data = csv.reader(file)
#첫번재 열의 첫번째 행 무시하기
next(data)
#첫번재 열의 두번째 행 무시하기
next(data)
# 행을 체크하기 위한 변수
column = 0
# 긍정적인 질문 행
positive_list = [1, 2, 4, 5, 7, 8]
# 부정적인 질문 행
negative_list = [0, 3, 6, 9, 10, 11, 12]
# 긍정적 수치
positive = 0;
# 부정적 수치
negative = 0;
# 1번~23번 열 체크하기 위한 for문
for row in data :
for idx in range(1, 24) :
# 긍정적인 질문이면
if column in positive_list :
# 질문의 답을 이용해서 각각의 긍정, 부정수치를 누적해서 저장
if ((idx % 5 == 4) or (idx % 5 == 0)) and (row[idx] != '-') :
positive += float(row[idx])
if ((idx % 5 == 1) or (idx % 5 == 2)) and (row[idx] != '-'):
negative += float(row[idx])
# 부정적인 질문이면
if column in negative_list :
# 질문의 답을 이용해서 각각의 긍정, 부정수치를 누적해서 저장
if ((idx % 5 == 1) or (idx % 5 == 2)) and (row[idx] != '-'):
positive += float(row[idx])
if ((idx % 5 == 4) or (idx % 5 == 0)) and (row[idx] != '-') :
negative += float(row[idx])
column += 1 # 다음 행 값으로 변경
file.close()
#print("긍정적 : {}".format(positive))
#print("부정적 : {}".format(negative))
import matplotlib.pyplot as plt
plt.rc('font', family = 'Malgun Gothic') # 한글 지원하는 폰트 설정 코드
plt.title('SNS~')
plt.axis('equal')
plt.pie([positive, negative], labels = ["긍정적", "부정적"], autopct = '%.1f%%')
plt.legend()
plt.show()
----------------------SNS 이용률 및 유형별 이용현황 원형그래프------------------
1.SNS 2개 선택해서 이용율 꺽은선 그래프로 그리고 앞으로 많이 사용될 SNS 유형 예측하기
'(학) (공) (파)' 카테고리의 다른 글
01.30(15일차) (1) | 2024.01.30 |
---|---|
01.29(14일차) -2 (0) | 2024.01.30 |
01.29(14일차) (0) | 2024.01.30 |
01.26(13일차) (1) | 2024.01.26 |
01.25(12일차) (0) | 2024.01.25 |