Pandas
Pandas 설치
파이썬[Python] Pandas 설치하기(pip), 아나콘다(Anaconda)설치 하기
이번 포스팅은 데이터 과학 및 머신러닝에서 많이 사용하는 Pandas 모듈에 대해서 설치 하는 방법에 대해서 이야기를 드리고자 합니다. 실제 저의 경우 Pandas, Numpy등 이런 별도의 모듈에 대해서 가
appia.tistory.com
Pandas Data Type
- Series : list
- DataFrame : Dictionary
DataFrame
a | b | c | |
1 | 4 | 5 | 6 |
2 | 7 | 8 | 9 |
3 | 10 | 11 | 12 |
df1 = pd.DataFrame(
{'a': [4,5,6],
'b': [7,8,9],
'c': [10,11,12]},
index = [1,2,3])
print(df1)
Pandas File Read and Write by Pandas
import pandas as pd
rfname = 'supplier.csv'
# CSV File Read by Pandas
# supplier.csv 파일을 읽어오기
data_frame = pd.read_csv(rfname)
print(data_frame)
# CSV File Write by Pandas
# supplier-pd.csv 파일을 만드는 코드
wfname = 'supplier-pd.csv'
data_frame.to_csv(wfname, index=False)
loc, iloc 함수
#loc()
print(data_frame.loc[:,'Part Number':'Purchase Date'])
#print(data_frame.loc[df['Cost']>600.0, ['Cost','Supplier Name'])
print(data_frame.loc[data_frame['Part Number']>2000, ['Cost','Supplier Name']])
#iloc()
print(df.iloc[2:6]) # 2~5 rows
print(df.iloc[:,[1,3]]) # all rows, 1,3 columns
data filtering
# Supplier Z
isZ = data_frame['Supplier Name']=='Supplier Z'
print(data_frame[isZ])
isZ = data_frame['Supplier Name'].str.endswitch('Z')
print(data_frame[isZ])
isZ = data_frame['Supplier Name'].str.contains('Z')
print(data_frame[isZ])
# Supplier Z 중에 cost가 600 이상인 데이터
data_frame['Cost'] = data_frame['Cost'].str.strip('$').astype(float)
z600 = data_frame.loc[(data_frame["Supplier Name"].str.contains('Z')) & (data_frame['Cost']>600.0),:]
print(z600)
*kagle 무료 데이터 웹'
선그래프
import matplotlib.pyplot as plt
x= [1,2,3,4,5]
y = [1,4,9,16,25]
plt.plot(x, y, linewidth=3)
plt.show()
'PYTHON' 카테고리의 다른 글
File I/O, 예외처리 개념 (0) | 2021.11.19 |
---|---|
Docstring, Scope, Module, File I/O 개념 (0) | 2021.11.12 |
Set, 집합, Function, Parameter, Argument, Return 개념 (0) | 2021.11.05 |