pandas는 데이터 분석 라이브러리로 dataframe을 주로 다루기 위한 라이브러리이다
![](https://blog.kakaocdn.net/dn/ZtMZP/btszCEIxcqL/8r3kRk2M5qUQFWa8kmCQk1/img.jpg)
pandas 설치 명령어
pip install pandas
Create an alias with the as keyword while importing
import pandas as pd
Pandas Dataframe 만들기
EXAMPLE
mydataset = {
'cars': ["BMW", "Volvo", "Ford"],
'passings': [3, 7, 2]
}
myvar = pd.DataFrame(mydataset)
print(myvar)
결과
cars passings
0 BMW 3
1 Volvo 7
2 Ford 2
Dataframe에서 특정 컬럼이나 로우(인덱스) 선택하기
column을 조회할때 df['column'], row를 조회할 때는 df.ix[index]를 많이 사용
Dataframe생성
import pandas as pd
data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}
#load data into a DataFrame object:
df = pd.DataFrame(data)
print(df)
RESULT
calories duration
0 420 50
1 380 40
2 390 45
1) specific column or row select[선택하기]
#refer to the row index:
print(df.loc[0])
RESULT - Return 0
calories 420
duration 50
Name: 0, dtype: int64
2) specific column or row select[선택하기]
#use a list of indexes:
print(df.loc[[0, 1]])
RESULT - Return row 0, 1
calories duration
0 420 50
1 380 40
csv파일 읽기
import pandas as pd
df = pd.read_csv('data.csv')
print(df.to_string())
**pandas버전 확인
import pandas as pd
print(pd.__version__)
사진: Unsplash의billow926
728x90
반응형
'PYTHON' 카테고리의 다른 글
PANDAS-잘못된 형식의 데이터 제거,변경하기[PYTHON개발] (0) | 2023.11.02 |
---|---|
PANDAS-빈 데이터 셀 제거하기[PYTHON개발] (0) | 2023.11.02 |
PYTHON 클래스 상속[PYTHON개발] (1) | 2023.11.02 |
파이썬 클래스와 객체[PYTHON개발] (0) | 2023.11.01 |
PYTHON 함수 선언[PYTHON개발] (1) | 2023.11.01 |