개발자 뺚
[Python] pandas 모듈(Module) 자료구조(Data Structure) 본문
import pandas as pd
pandas 모듈(Module)의 전처리문이다. as 문은 대신해서 사용한다는 의미로 pandas 모듈을 가져와서 pd라는 이름으로 사용한다는 것을 의미한다.
1. 시리즈(Series)
1차원 리스트의 각 열에 대응되는 인덱스(Index)를 가지는 구조
pd.Series(list1)
pd.Series(list1, index = list2)
# example
list1 = [3000, 2000, 2500]
list2 = ["apple", "orange", "banana"]
print(pd.Series(list1), end = "\n\n")
print(pd.Series(list1, index = list2))
# terminal
0 3000
1 2000
2 2500
apple 3000
orange 2000
banana 2500
2. 데이터프레임(DataFrame)
2차원 리스트의 각 행과 열에 대응되는 인덱스(Index)를 가지는 구조
pd.DataFrame(list1)
pd.DataFrame(list1, index = list2)
pd.DataFrame(list1, index = list2, columns = list3)
# example
list1 = [[3000, "20%"], [2500, "10%"]]
list2 = ["apple", "banana"]
list3 = ["price", "discount"]
print(pd.DataFrame(list1), end = "\n\n")
print(pd.DataFrame(list1, index = list2), end = "\n\n")
print(pd.DataFrame(list1, index = list2, columns = list3))
# terminal
0 1
0 3000 20%
1 2500 10%
0 1
apple 3000 20%
banana 2500 10%
price discount
apple 3000 20%
banana 2500 10%
'Information > Python' 카테고리의 다른 글
[Python] 아스키 코드(ASCII) 함수 (0) | 2023.09.02 |
---|---|
[Python] 리스트(List) 메서드 (0) | 2023.08.30 |
[Python] random 모듈(Module) (6) | 2023.07.16 |
[Python] datetime 모듈(Module) (0) | 2023.07.16 |
[Python] 문자열(String) 메서드 (4) | 2023.07.16 |