02 figure_axes

Figure_Axes

  • matplotlib을 사용하여 그림을 그리기 위해서 기본적으로 Figure(windows(창)의 개념) 객체와 Figure 객체에 포함되는 하나 이상의 Axes(subplot)를 생성해야 한다.
    • matplotlib.pyplot의 하위 함수나 DataFrame.plot 메소드를 호출할때는 자동으로 하나의 Figure와 Axes가 생성이 된다.
  • Figure객체와 Axes객체는 여러개의 subplot을 관리할때 생성한다.
  • Figure Docs에 보면 Figure는 모든 plot의 모든 요소를 포함하는 최상위 객체이다. (the figure module provides the top-level Artist, the Figure, which contains all the plot elements)
  • Axes Docs에 보면 Axes는 Figure의 대부분의 기능을 가지고 있으며(The Axes contains most of the figure element) Axis, Tick, Line2D, Text, Polygon 같은 속성을 조정한다.
  • Figure와 Axes관련 중요 함수를 보면
    • pyplot.subplot docs를 보면 subplot함수는 Axes 객체를 반환한다. subplot은 nrows, ncols, plot_number의 순서대로 인수를 같는다.

Continue reading 02 figure_axes

01 matplotlib_pyplot

matplot_pyplot

  • matplotlib은 파이썬에서 데이터를 시각화하는 대표적인 패키지이다.
  • pyplot은 matplotlib의 하위라이브러로 Bar, Scatter, Historgam, Box 같은 Plot을 쉽게 사용 할 수 있게 해준다. (The matplotlib.pyplot module contains, functions that allow you to generate many kinds of plots quickly)
  • The matplotlib.pyplot docs 를 보면 130여개의 function을 제공하는데 대표적인 function들을 보면

    • plot: 대표적인 함수루 축을 기준으로 선을 그림 (Plot lines and/or markers to the Axes)
    • bar:Make a bar plot.
    • scatter:Make a scatter plot of x vs y.
    • hist:Plot a histogram.
    • boxplot:Make a box and whisker plot.
    • stackplot:Draws a stacked area plot.
    • pie:Plot a pie chart.
  • DataFrame.plot은 DataFrame의 메소드로 DataFrame에서 편하게 matplotlib 함수들을 호출하게 해준다.DataFrame.plot docs

    • kind라는 매개변수를 통해서 그래프이 형태를 선택할 있다.
    • 그래프의 형태에 따라 수많은 매개변수가 존재한다.

Continue reading 01 matplotlib_pyplot

20 Groupby Aggregation

GroupBy Aggregate

  • Groupby 객체의 Aggregate 메소드 docs 는 그룹함수들을 수집하여 한번에 처리하는 기능으로 DataFrameGroupBy.agg(arg, * args, kwargs)로 표현된다.
    • args에 string, tuple, dicionary, list 를 입력할 수 있다.
  • Agg(Aggregate) 메소드는 다음 용도로 사용된다.

    • count, sum, mean, min, max, first, last같은 그룹함수를 동시에 사용할 경우에
    • 자신만의 데이터 집계함수를 사용하기 위해(즉, 사용자 집계함수)
  • Agg를 사용하는 대표적인 표현으로는 컬럼과 적용 집계함수를 딕셔너리로 만들고 그 딕셔너리를 튜플로 만들어 Agg메소드의 인자로 넣는 방법이다.

    • ex) tuple_dic = {2000:['count','mean'], 2001:['max']}
    • ex) df.groupby(['Team','Season']).agg(tuple_dic)

Continue reading 20 Groupby Aggregation

19 Groupby

GroupBy

  • 데이터베이스는 Group by절을 사용하여 Group으로 나눈후 집합(Group) 함수(count, avg, sum) 등을 사용할 수 있는데 Pandas에서도 이와 비슷한 개념인 Groupby 메소드가 존재함
  • Groupby Docs에 정의를 보면 매퍼에 의해 만들어진 Groupby 객체로 정의 됨(Group series using mapper (dict or key function, apply given function to group, return result as series) or by a series of columns.

    • grouped = df.groupby['col1'] groupby메소드를 사용하여 groupby 객체가 생성되고.
    • grouped.count(), grouped.mean(), grouped.sum()와 같이 생성된 groupby에서 집합함수를 적용할 수 있음.
  • groupby는 다음과 같은 iteration을 제공함

    • for name, group in df.groupby()

Continue reading 19 Groupby

Pagination


© 2017. All rights reserved.

Powered by ZooFighter v0.12