[Pandas]데이터 구조, 분석
·
Pandas
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119import pandas as pd ###데이터 정보 확인####데이터 미리 살펴보기#data= pd.read_csv("C:/Users/ZenBook/Desktop/code/sample/part3/auto-mpg.csv")print(data.head()) #head(..
[Pandas]데이터 저장하기
·
Pandas
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758import pandas as pd ###데이터 저장하기####CSV 파일로 저장##to_csv() 메소드 사용# route = 'C:/Users/ZenBook/Desktop/code/sample/part2'data = {'이름':['한건희', '안재민', '심지민', '이영제'], '나이':[11, 13, 25, 98], '직업':['학생', '교사', '교수', '가수']}df = pd.DataFrame(data)df.set_index('이름', inplace= True)print(df) #df.to_csv('C..
[Pandas]웹에서 데이터 가져오기
·
Pandas
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 29 30 31 32 33 34 35 36 37 38 39 40 41 import pandas as pd ###웹에서 가져오기### #HTML 웹 페이지에서 표 가져오기# #read_html() 메소드 사용, html 웹페이지에 있는 표를 데이터프레임으로 변환한 후 리스트의 형태로 반환한다# #pip install lxml# #터미널에서 lxml을 설치해야 한다# html = pd.read_html('C:/Users/ZenBook/Desktop/code/sample/part2/sample.html') print(html) print(len(html)) ##sample.ht..
[Pandas]외부 파일 불러오기
·
Pandas
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 import pandas as pd ###외부 파일 불러오기### ''' 파일 포멧 Reader Writer CSV read_csv to_csv JSON read_json to_json HTML read..
[Pandas]데이터프레임 연산
·
Pandas
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 29 30 import pandas as pd ###데이터프레임 연산### #데이터프레임의 연산은 시리즈의 연산의 확장이라고 생각하면 된다# #데이터프레임과 숫자의 연산# a = pd.DataFrame({'c0':[100, 50, 30], 'c1':[30, 50, 50], 'c2':[100, 20, 70]}, index=['r0', 'r1', 'r2']) a_add = a + 10 print(a_add) ''' c0 c1 c2 r0 110 40 110 r1 60 60 30 r2 40 60 80 ''' #데이터프레임과 데이터프레임의 연산# a = pd.DataFrame({'..