コード例 #1
0
import os, re, usecsv

total = usecsv.opencsv('popSeoul.csv')

result = usecsv.switch(total)

print(result[:5])
コード例 #2
0
import os, re, usecsv

os.chdir(
    r'D:\VisualStudioCode\Python\Do_it_Python_Programming_in_Life\chapter04')
apt = usecsv.switch(usecsv.opencsv('apt_202109.csv'))

# print(apt[:3])
# print(len(apt))

# for i in apt[:6]:
#     print(i[0])

# for i in apt[:6]:
#     print(i[0], i[4], i[-4])

# for i in apt:
#     try:
#         if i[5] >= 120 and i[-4] <= 30000 and re.match('강원', i[0]):
#             print(i[0], i[4], i[-4])

#     except:
#         pass

new_list = []
for i in apt:
    try:
        if i[5] >= 120 and i[-4] <= 30000 and re.match('강원', i[0]):
            new_list.append([i[0], i[4], i[-4]])
    except:
        pass
コード例 #3
0
import usecsv
import numpy as np
import os
os.chdir(r'C:\Users\alstn\PycharmProjects\data-analysis-Pandas-Numpy\Numpy')
# quest.csv 저장한 경로

# 파일을 열어 숫자 원소를 실수형으로 바꾼 후 배열 형태로 저장
quest = np.array(usecsv.swith(usecsv.opencsv('quest.csv')))

print(quest)

# 4보다 큰 점수를 만점인 5점으로 동기화
quest[quest > 5] = 5
# 결과물을 저장
usecsv.writecsv('result.csv', list(quest))
コード例 #4
0
# stocktoday에서 csv파일 가져와서 그 안에 있는 url 정보만으로 챠트 이미지 저장하기 성공
from bs4 import BeautifulSoup as bs
import requests, re, usecsv, datetime, os
headers = {
    "User-Agent":
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36'
}
#애이프로바이오 url을 가져옴
stocktoday = usecsv.opencsv('stocktoday1220.csv')
#차트 이미지 다운받기 성공
os.chdir(r'C:\Users\ERC\Documents\GitHub\fast_campus\basic_scaping\stock\img')
# stocktoday url 모두에서 찾아서 자동으로 챠트 이미지 다운로드 받기
for url in stocktoday:
    headers = {
        "User-Agent":
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36'
    }
    soup = bs(requests.get(url[1], headers=headers).text, 'lxml')
    for i in soup.find_all('div', {'class': 'chart'}):
        #주식이름 url[0]을 이름으로 하는 jpg 파일명 생성
        with open(url[0] + 'chart.jpg', 'wb') as handler:
            # img에서 src라는 요소 찾아서 requests로 불러낸 후 그것의 content를 파일에 쓰라고 명령
            handler.write(requests.get(i.find('img').get('src')).content)
コード例 #5
0
import os, usecsv
import numpy as np

os.chdir(r'D:\VisualStudioCode\Python\Do_it_Python_Programming_in_Life\chapter05')
quest = np.array(usecsv.switch(usecsv.opencsv('quest.csv')))
print(quest)

print(quest[quest > 5])
quest[quest > 5] = 5
print(quest)

usecsv.writecsv('resultcsv.csv', list(quest))

result = np.array(usecsv.switch(usecsv.opencsv('resultcsv.csv')))
print(result)
コード例 #6
0
import usecsv, os, re
from switch import switch
os.chdir(
    r'C:\Users\지재지\OneDrive - Office Everyday\MyScript\python\manuscript_Book\Data\realestate'
)

apt = switch(usecsv.opencsv('apt_201910.csv'))
#apt = usecsv.makenewlist(apt)
#print(apt[3])
header = [
    '시군구', '번지', '본번', '부번', '단지명', '전용면적(㎡)', '계약년월', '계약일', '거래금액(만원)', '층',
    '건축년도', '도로명'
]
newlist = []
for i in apt:
    try:
        #조건1: 100㎡ 이상, 10층에서 15층 사이, 5억이상
        #if i[5] > 100 and i [-3] > 10 and i [-3] < 15 and i[-4] > 50000:
        #조건2: 130㎡ 이상,4억 이하
        #if i[5] > 130 and i[-4] < 30000:
        #출력조건: 지역, 단지명, 크기, 층수, 거래금액
        #newlist.append([re.match('[가-힣]+ [가-힣]+',i[0]).group(), i[4], i[5], i[-3], i[-4]])
        #조건3  단지명 아이파크
        #if re.search('래미안',i[4]):
        #출력조건: 지역, 단지명, 크기, 층수, 거래금액
        #newlist.append([re.match('[가-힣]+ [가-힣]+',i[0]).group(), i[4], i[5], i[-3], i[-4]])
        #조건4: 20억 이상
        if i[-4] > 150000:
            #출력조건: 지역, 단지명, 크기, 층수, 거래금액
            newlist.append([
                re.match('[가-힣]+ [가-힣]+', i[0]).group(), i[4], i[5], i[-3],
コード例 #7
0
import os, re, usecsv

apt = usecsv.switch(usecsv.opencsv('apt_201910.csv'), enc='latin1')

print(apt[:3], len(apt))

# Fail to solve encoding issue...
# I did `iconv` and `open(..., encoding=<encoding>)` but they do not worked.
コード例 #8
0
ファイル: 04-4.py プロジェクト: EricSeokgon/pythonProject
import csv, os, re

os.chdir(r'C:\Users\sklee\PycharmProjects\pythonProject\chaptor04')
import usecsv

apt = usecsv.switch(usecsv.opencsv('apt_202012.csv'))

print(apt[:3])

print(len(apt))

for i in apt[:6]:
    print(i[0])

for i in apt[:6]:
    print(i[0], i[4], i[-4])

new_list = []
for i in apt:
    try:
        if i[5] >= 120 and i[-4] <= 30000 and re.match('강원', i[0]):
            print(i[0], i[4], i[-4])
    except:
        pass
usecsv.writecsv('over120_lower3000.csv', new_list)
コード例 #9
0
import os, re
import usecsv

os.chdir('C:\Learning\Python\eleven_projects_python\data_sources')

fhand = usecsv.opencsv('popSeoul.csv')
new_pop = usecsv.switch(fhand)
# print("new_pop",new_pop)



'1. 서울시 전체 외국인 비율 계산'

tot = new_pop[1]
ratio = (tot[2] / (tot[1]+tot[2])) * 100
f_ratio = round(ratio, 2)
# print("foreign_ratio:", f_ratio)




'''
2. 각 구의 외국인 비율 계산

- try ~ except 구문으로 문자열일 경우는 pass 예외처리 하기

for lst in new_pop:
  ratio = 0

  try:
    ratio = (lst[2] / (lst[1] + lst[2])) * 100
コード例 #10
0
import os
os.chdir(r'C:\Users\ERC\Documents\GitHub\PythonBasic\csv')
import usecsv
ad = [[1, 2, 3], ['우리', '나라', '만세'], ['나는', '우리나라가', '좋다']]
usecsv.writecsv('new_write_file.csv', ad)
total = usecsv.opencsv('new.csv')
print(total)