Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 반복문
- data
- Machine Learning
- len()
- analizer
- 최솟값
- DataFrame
- 분류 결과표
- IN
- list
- numpy
- dendrogram
- insert()
- Python
- append()
- nan
- wcss
- del
- DataAccess
- matplotlib
- function
- count()
- 최댓값
- sklearn
- Dictionary
- hierarchical_clustering
- string
- 덴드로그램
- elbow method
- pandas
Archives
- Today
- Total
개발공부
[Python] Pandas Series 생성, 데이터 액세스, 산술 연산 본문
Pandas 장점
- Allows the use of labels for rows and columns
- 기본적인 통계데이터 제공
- NaN values 를 알아서 처리함.
- 숫자 문자열을 알아서 로드함.
- 데이터셋들을 merge 할 수 있음.
- It integrates with NumPy and Matplotlib
Pandas Series 데이터 생성
>>> import pandas as pd
>>> index = ['eggs', 'apples', 'milk', 'bread']
>>> data = [30, 6, 'Yes', 'No']
# data로 만들기
>>> x = pd.Series(data = data)
>>> x
0 30
1 6
2 Yes
3 No
dtype: object
# data와, index로 만들기
>>> groceries = pd.Series(data = data, index = index)
>>> groceries
eggs 30
apples 6
milk Yes
bread No
dtype: object
# data, index, columns로 만들기
>>> pd.DataFrame(groceries, columns=['h'])
h
eggs 30
apples 6
milk Yes
bread No
pandas series 데이터 억세스
>>> groceries
eggs 30
apples 6
milk Yes
bread No
dtype: object
>>> groceries[0]
30
>>> groceries['eggs']
30
>>> groceries[['eggs', 'bread']]
eggs 30
bread No
dtype: object
groceries[-1]
'No'
>>> groceries
eggs 30
apples 6
milk Yes
bread No
dtype: object
>>> groceries['apples' : ]
apples 6
milk Yes
bread No
dtype: object
>>> groceries['apples' : 'milk']
apples 6
milk Yes
dtype: object
>>> groceries[1 : 2 + 1]
apples 6
milk Yes
dtype: object
산술연산
>>> index = ['apples', 'oranges', 'bananas']
>>> data = [10, 6, 3,]
>>> fruits = pd.Series(data = data, index = index)
>>> fruits
apples 10
oranges 6
bananas 3
dtype: int64
# 전체 데이터를 5씩 더하기
>>> fruits = fruits + 5
>>> fruits
apples 15
oranges 11
bananas 8
dtype: int64
# oranges만 2 빼기
>>> fruits['oranges'] = fruits['oranges'] - 2
>>> fruits
apples 15
oranges 9
bananas 8
dtype: int64
# apples 와 bananas를 3씩 더하기
# 반영해 주세요
>>> fruits
apples 15
oranges 9
bananas 8
dtype: int64
>>> fruits[['apples', 'bananas']] = fruits[['apples', 'bananas']] + 3
>>> fruits
apples 18
oranges 9
bananas 11
dtype: int64'Python > Pandas' 카테고리의 다른 글
| [Python]Pandas 카테고리컬 데이터 확인하기, 이를 묶어 처리하기 groupby() (0) | 2022.05.03 |
|---|---|
| [Python] Pandas Dataframe NaN 다루기 (0) | 2022.05.02 |
| [Python] Pandas Dataframe 인덱스, 컬럼명 변경하기(rename()), 컬럼을 인덱스로 사용하기(set_index(),reset_index()) (0) | 2022.05.02 |
| [Python] Pandas Dataframe 열과 행 생성, 삭제(append(), drop()) (0) | 2022.05.02 |
| [Python] Pandas Dataframe 생성, csv읽기, 저장하기, 데이터 액세스 (0) | 2022.05.02 |