전체 글

전체 글

    [Python] Indexing, Selecting & Assigning

    [Python] Indexing, Selecting & Assigning

    1. Native accessors Python 객체에 indexing을 통해 값을 검색할 수 있지만, 판다스 라이브러리는 좀 더 쉬운 method를 제공한다. # View all data reviews # View Series value from specific column reviews.country reviews['country'] # View value from specific columns and rows acting like dictionary reviews['country'][0] 2. Indexing in pandas 판다스는 loc와 iloc라는 접근 연산자를 가지고 있다. 2.1 Index-based selection 판다스는 두가지 형태의 인덱스를 수행할 수 있다. 첫번째는 숫자 인덱..

    [Python] Creating, Reading and Writing

    [Python] Creating, Reading and Writing

    1. Getting started 판다스 라이브러리를 사용하려면 import ... as 를 사용하여 libary를 호출한다. import pandas as pd 2. Creating data 판다스에는 두 가지 핵심 객체가 있다 : DataFrame과 Series 이다. 2.1 DataFrame 데이터 프레임 객체는 테이블이다. 각각의 값들에 대한 배열을 형성하며, 행과 열의 구조를 가지고 있다. pd.DataFrame({'Yes' : [50, 21], 'No' : [131, 2]}) 데이터프레임의 각 값은 리스트와 동일하게 다양한 타입의 데이터를 저장할 수 있다. pd.DataFrame({'Bob' : ['I liked it.', 'It was awful.'], 'Sue' :['Pretty good...

    [Python] Working with External Libraries

    [Python] Working with External Libraries

    1. Imports import math 'math'는 module이다. module은 다른사람에 의해 정의된 변수들의 집합이다. dir()함수를 통해서 module안에 있는 built-in function들의 이름을 확인 가능하다. # See all the names in math dir(math) # access these variables math.pi math.log(32,2) 2. Other import syntax 이러한 module은 as 뒤에 별칭을 통해 좀더 간단하게 호출할 수 있다. import pandas as pd 3. Submodlues There are some submodules in variables such as below. # Import library import num..

    [Python] Strings and Dictionaries

    [Python] Strings and Dictionaries

    1. Strings Double quote(")는 string이 single quote(')를 포함하고 있을 때 편하다. 만일 string이 double quote(")를 포함하고 있다면 string에 single quote(')를 덮어주면 된다. print("Pluto's a planet!") print('My dog is named "Pluto"') 2. Strings are sequences String은 문자의 연속이라고 생각할 수 있다. 따라서 list에 적용할 수 있는 idexn는 동일하게 string에 적용된다. # Indexing planet = 'Pluto' planet[0] # result is 'P' # Slicing planet[-3:] # result is 'uto' 3. Stri..