Пример #1
0
import os, re, usecsv

os.chdir(
    r'D:\VisualStudioCode\Python\Do_it_Python_Programming_in_Life\chapter04')
total = usecsv.opencsv('popSeoul.csv')
newPop = usecsv.switch(total)

# print(newPop[:4])

# i = newPop[1]
# print(i)

# foreign = round(i[2] / (i[1] + i[2]) * 100, 1)
# print(foreign)

# for i in newPop:
#     foreign = 0
#     try:
#         foreign = round(i[2] / (i[1] + i[2]) * 100, 1)
#         print(i[0], foreign)
#     except:
#         pass

# new = [['구', '한국인', '외국인', '외국인 비율(%)']]

# i = newPop[1]
# foreign = round(i[2] / (i[1] + i[2]) * 100, 1)

# new.append([i[0], i[1], i[2], foreign])

# print(new)
Пример #2
0
import os, re, usecsv

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

result = usecsv.switch(total)

print(result[:5])
import os, re, csv
import usecsv

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

'1. data_sources폴더에서 오피스텔가격 csv 파일 불러서 CSV형 리스트로 전환 후(usecsv.opencsv_cp949), 문자형을 실수형으로 변경(usecsv.switch)'

fhand = usecsv.opencsv_cp949('officetel_price.csv')
# print(fhand[:10])

officetel_info = usecsv.switch(fhand)
# print(officetel_info[:10])

print("count_deal:", len(officetel_info))
# 7667, 2020년 12월 한달 간 오피스텔 거래 수
'''
2. 슬라이싱으로 원하는 자료 출력하기


'''

# for i in officetel_info[:30]:
#   print(i[0], i[4], i[5], i[6], i[9], i[10])

'3. 궁금한 실거래 조건 검색해서 csv로 저장하기'

count = 0
the_officetel = []
print('내가 궁금한 실거래 조건')
print("오피스텔 헤더:", officetel_info[0])
the_officetel.append(officetel_info[0])
Пример #4
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
Пример #5
0
    url = (
        'https://www.coupang.com/np/search?q=%EB%85%B8%ED%8A%B8%EB%B6%81&channel=user&component=&eventCategory=SRP&trcid=&traid=&sorter=scoreDesc&minPrice=&maxPrice=&priceRange=&filterType=&listSize=36&filter=&isPriceRange=false&brand=&offerCondition=&rating=0&page='
        + str(page) +
        '&rocketAll=false&searchIndexingToken=1=4&backgroundColor=')
    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'
    }
    res = requests.get(url, headers=headers)
    soup = bs(res.text, 'lxml')
    for i in soup.find_all('li', {'class': 'search-product'}):
        name = i.find('div', {'class': 'name'}).text
        #print('https://www.coupang.com'+i.find('a').get('href') )
        try:
            new.append([
                name,
                i.find('strong', {
                    'class': 'price-value'
                }).text,
                i.find('span', {
                    'class': 'rating-total-count'
                }).text, 'https://www.coupang.com' + i.find('a').get('href')
            ])
        except:
            pass

import usecsv
new = usecsv.switch(new)
usecsv.writecsv('coupang(p)_suc.csv', new)
# 상품정보 담는 데까지 성공
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)
Пример #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
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