본문 바로가기

파이썬. 데이터분석112

matplotlib : 막대그래프와 꺾은선그래프 동시에 그리기(twinx) https://www.youtube.com/watch?v=PjhlUzp_cU0 나도코딩 데이터분석 마지막파트 여기서 배운것들을 토대로 좀 더 찾아서 추가함 stateless 방식 ax1.legend(bbox_to_anchor=(1, 0.9),fontsize=18) - legend 상세한 위치설정 ax1.yaxis.set_label_coords(0, 1) - y축label 상세한 위치설정 ax1과 ax2 둘다 legend를 띄우면 겹쳐있어서 ax1(출생아 수)의 legend위치를 바꿨다 ax2 = ax1.twinx() 뜻 : ax2는 ax1와 같은 축을 공유한다. fig, ax1 = plt.subplots(figsize=(12,7)) ax1.bar(df.index, df['출생아 수'], label='출생.. 2022. 7. 16.
matplotlib : ax. plt. 문법차이 https://wooono.tistory.com/297 [Matplotlib] figure, subplot 차이 matplotlib.pyplot.figure reference https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.html example import matplotlib.pyplot as plt # figure 크기 설정 plt.figure(figsize=(15,7)) # grid 설정 p.. wooono.tistory.com matplotlib.pyplot plt.이후 메서드 https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.html matplotlib.pyplot — Matplot.. 2022. 7. 16.
pd.read_excel : 경로는 고정, 파일명만 바꾸기 fileroute 경로는 고정시켜놓고 filename만 바꿔서하면 실무에서 편함 2022. 7. 16.
matplotlib : plt.subplot 여러 그래프 동시에 보여주기 2 fig,ax 튜플보다 그래프 설정하는 문법이 좀 더 익숙해서 좋다. plt.figure(figsize=(20,20)) plt.subplot(2,2,1) plt.bar(index, dff_1['출고수량']) plt.title('요일별', fontsize=30) plt.xticks(index, label, fontsize=15) plt.subplot(2,2,2) plt.bar(index, dff_2['출고수량']) plt.title('요일별', fontsize=30) plt.xticks(index, label, fontsize=15) plt.subplot(2,2,3) plt.bar(index, dff_3['출고수량']) plt.title('요일별', fontsize=30) plt.xticks(index, l.. 2022. 7. 14.
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.