Фишки Python
29 subscribers
2 photos
3 files
29 links
Всё что ты хотел узнать, но ленился спросить.

Декораторы, итераторы и контракты.
Download Telegram
Парсинг даты из кучи вариантов - parsedatetime
import parsedatetime as pdt

cal = pdt.Calendar()

examples = [
"2016-07-16",
"2016/07/16",
"2016-7-16",
"2016/7/16",
"07-16-2016",
"7-16-2016",
"7-16-16",
"7/16/16",
"19 November 1975",
"19 November 75",
"19 Nov 75",
"tomorrow",
"yesterday",
"10 minutes from now",
"the first of January, 2001",
"3 days ago",
"in four days' time",
"two weeks from now",
"three months ago",
"2 weeks and 3 days in the future",
]

print('{:30s}{:>30s}'.format('Input', 'Result'))
print('=' * 60)

for e in examples:
dt, result = cal.parseDT(e)
print('{:<30s}{:>30}'.format('"' + e + '"', dt.ctime()))
Input Result
============================================
"2016-07-16" Sat Jul 16 16:25:20 2016
"2016/07/16" Sat Jul 16 16:25:20 2016
"2016-7-16" Sat Jul 16 16:25:20 2016
"2016/7/16" Sat Jul 16 16:25:20 2016
"07-16-2016" Sat Jul 16 16:25:20 2016
"7-16-2016" Sat Jul 16 16:25:20 2016
"7-16-16" Sat Jul 16 16:25:20 2016
"7/16/16" Sat Jul 16 16:25:20 2016
"19 November 1975" Wed Nov 19 08:41:38 1975
"19 November 75" Wed Nov 19 08:41:38 1975
"19 Nov 75" Wed Nov 19 08:41:38 1975
"tomorrow" Tue Jun 21 09:00:00 2016
"yesterday" Sun Jun 19 09:00:00 2016
"10 minutes from now" Mon Jun 20 08:51:38 2016
"the first of January, 2001" Mon Jan 1 08:41:38 2001
"3 days ago" Fri Jun 17 08:41:38 2016
"in four days' time" Fri Jun 24 08:41:38 2016
"two weeks from now" Mon Jul 4 08:41:38 2016
"three months ago" Sun Mar 20 08:41:38 2016
"2 weeks and 3 days in the future" Thu Jul 7 08:41:38 2016
Forwarded from Python Textbooks (Igor A. Kamyshev)
Data Visualization with Python and JS – Kyran Dale (en) 2016

Рассмотрен стек визуализации данных: Python и JS, библиотеки Pandas и D3.

Книга предоставлена @frontend_textbooks.

#middle
Scrapy - парсер всего и вся в Web
Pandas - обработка и анализ данных
Matplotlib - визуализация данных на Python 2D/3D
Seaborn - визуализация данных поверх matplotlib, красивые графики
Crossfilter - js data-processing libraries, быстрая фильтрация строк/столбцов в датасете
D3.js - визуализация на js
autoenv - переопределяет cd и автоматом подтягивает текущий .env
Selenium + PhantomJS
Scrapy можно попробовать scrapyjs
import sqlite3
import requests
from lxml import html
from lxml import etree
from datetime import datetime


def log(*s):
print("{0} [LOG]:".format(datetime.now()), *s)


def main():
r = requests.get("https://www.av ito.ru/krasnodar/avtomobili/vaz_lada?view=list&radius=0&s_trg=3&f=188_893b&i=1")
if r.status_code != 200:
log("Status code check fail: {}".format(r.status_code))
tree = html.fromstring(r.text)
res = []
l = tree.xpath('//div[@itemtype="http://sch ema.org/Product"]')
for p in l:
id = p.attrib.get('id')
price = p.xpath('.//p[@itemprop="price"]')[0].attrib.get('content')
mileage = p.xpath('div[@class="mileage"]')[0].text
desc = p.xpath('meta[@itemprop="description"]')[0].attrib.get('content')
res.append((id, mileage, desc))


if name == "main":
main()
Jupyter Notebook

python -m pip install --upgrade pip
python -m pip install jupyter

pip install numpy pandas scikit-learn matplotlib seaborn

jupyter notebook
Python для сложных задач (ru) Дж. Вандер Плас