본문 바로가기

분류 전체보기259

matplotlib : 산점도 scatter scatter 프로토타입 sizes = df['학년'] plt.figure(figsize=(10,10)) plt.scatter(df['영어'], df['수학'], s= sizes * 500, c = df['학년'], cmap='Set3', alpha=0.9) plt.xlabel('영어 점수') plt.ylabel('수학 점수') plt.colorbar(ticks=[1, 2, 3], label='학년', shrink=0.8, orientation ='horizontal') 2022. 7. 14.
Numpy : np.where / if 함수역할 df['sex'] = np.where(df['sex'] == 3, np.nan, df['sex']) df 예시1 mpg['grade2'] = np.where(mpg['total'] >= 30, 'A', np.where(mpg['total'] >= 25, 'B',np.where(mpg['total'] >= 20, 'C', 'D'))) mpg['size'] = np.where((mpg['category'] == 'compact') | (mpg['category'] == 'subcompact') | (mpg['category'] == '2seater'), 'small', 'large') mpg['size'] = np.where(mpg['category'].isin(['compact','subcompact','.. 2022. 7. 14.
matplotlib : 원그래프(파이그래프) values = [30, 25, 20, 13, 10, 2] labels = ['Python', 'Java', 'Javascript', 'C#', 'C/C++', 'ETC'] plt.pie(values, labels= labels, autopct='%.2f%%', counterclock=False) plt.show() values = [30, 25, 20, 13, 10, 2] labels = ['Python', 'Java', 'Javascript', 'C#', 'C/C++', 'ETC'] explode = [0.05] * 6 plt.pie(values, labels= labels, autopct='%.2f%%', explode=explode, counterclock=False) plt.legend() pl.. 2022. 7. 13.
matplotlib : 다중 막대 그래프 여기서 그냥 이렇게하면 그래프들끼리 겹친다. width를 지정해준다. w=0.25에서 w를 0.5나 다른숫자로하니까 또 겹친다. 추측인데 그래프가 각자 3개씩이니까 0.33이하로해야 안겹치는것 같다. plt.figure(figsize=(14,7)) plt.title('학생별 성적', color='w') w = 0.25 plt.bar(index - w, df['국어'], width=w, label='국어') plt.bar(index, df['영어'], width=w, label='영어') plt.bar(index + w, df['수학'], width=w, label='수학') plt.legend() plt.xticks(index, df['이름']) plt.grid(axis='y') plt.show() 2022. 7. 13.
Pandas DataFrame : df.columns = [ ] 와 rename 열 이름 바꾸기. 열이름 바꾸는 방법이 2가지가 있는데   1. df.columns = [  ] 구문을 이용하는것.기존에 column이 8개였으면 순서를 바뀔때도 column 8개를 입력해야됨. 8개에서 7개로 바꾸고 이런건 안된다 2. rename 딕셔너리를 이용한 방법.보통 여러개 바꾸는것보다 1,2개 바꾸는 일이 많아서 주로 1번을 쓴다. -'국어' 열 이름을 '도덕'으로 바꿔보기- df.columns 를 치면 column 목록이 쫙 뜨는데 위에 list를 복사해서 'df.columns =' 옆에 붙여넣기하고 바꿔치기하고 싶은 이름을 바꿔넣으면 된다.  코딩좀 하신분들 강의보면 대부분 이런식으로 갈아끼워넣길래 정리   df.rename(columns = {'영어' : 'English', '수학' : 'Math'})아.. 2022. 7. 12.
matplotlib : 누적 막대그래프 plt.bar(df['이름'], df['국어'], label='국어') plt.bar(df['이름'], df['영어'], label='영어', bottom=df['국어']) plt.legend() plt.bar(df['이름'], df['국어'], label='국어') plt.bar(df['이름'], df['영어'], label='영어', bottom=df['국어']) plt.bar(df['이름'], df['수학'], label='수학', bottom=df['국어'] + df['영어']) plt.legend() plt.xticks(rotation=45) plt.show() 2022. 7. 12.
matplotlib : 막대 그래프별 색,xticks labels = ['강백호', '서태웅', '정대만'] values = [190, 187, 184] colors = ['r', 'g', 'b'] ticks=['1번학생', '2번학생', '3번학생'] plt.bar(labels, values, color=colors, alpha = 0.5, width=0.5) plt.ylim(175,195) plt.xticks(labels, ticks, rotation='45', color='crimson', fontsize=40) 2022. 7. 12.
지금까지 배운거 복습 : enumerate, grid, legend df 바로 plt.plot으로 그려본다. 밋밋하다 배운거 한가지씩 해보려고하니까 복잡해졌다. grid는 전역설정 방법이 plt.rcParams['axes.grid'] = True 십자무늬 grid가 생긴다. 나는 y축만하고싶어서 plt.grid(axis='y')로 했다 enumerate에 df['영어']같은 Series도 가능할까했는데 넣어보니까 됐다. plt.plot(df['지원번호'], df['영어'], label='영어점수', color = 'blue') plt.plot(df['지원번호'], df['수학'], label='수학점수', color = 'red') for idx, txt in enumerate(df['영어']): plt.text(df['지원번호'][idx], df['영어'][idx], .. 2022. 7. 11.