This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
url = 'https://nplus1.ru/' | |
page = requests.get(url) | |
soup = BeautifulSoup(page.text) | |
urls = [] | |
for link in soup.find_all('a'): | |
if '/news' in link.get('href'): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
hp = pd.read_excel("HP_one.xlsx") | |
hp.head() | |
hp_pivot = hp.pivot_table(index='Name', columns='Subject', values = 'Mark') | |
hp_pivot | |
hp.pivot(index='Name', columns='Subject', values = 'Mark') | |
hp_pivot.index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hp.groupby(['Name', 'Subject']) | |
hp2 = hp.groupby(['Name', 'Subject']).first() | |
hp2.stack() | |
stacked = pd.DataFrame(hp2.stack()) | |
stacked | |
stacked.index[0:6] | |
stacked.columns | |
stacked.iloc[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
harry = hp[hp['Name'] == 'Harry Potter'] | |
ron = hp[hp['Name'] == 'Ronald Weasley'] | |
pd.concat([harry, ron], axis = 1) | |
pd.concat([hp[['Name', 'Subject']], hp[['Mark', 'Comment']]], axis=1) | |
df1 = pd.read_excel("HP_two.xlsx") | |
df2 = pd.read_excel("HP_three.xlsx") | |
pd.merge(df1, df2, on=['Name', 'Subject']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
A = np.array([8, 2, 8]) | |
A.dtype | |
A.ndim | |
A.sort() | |
A | |
class Cauldron: | |
def __init__(self, size, material): | |
self.size = size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cauldron_Pers(Cauldron): | |
def __init__(self, size, material, owner, contents=[], mark=None): | |
super().__init__(size, material, contents) | |
self.owner = owner | |
self.mark = mark | |
my = Cauldron_Pers('medium', 'cooper', 'Alla') | |
my.owner | |
my.mark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from wordcloud import WordCloud | |
text = 'i solemnly swear i am up to no good mischief managed' | |
# определяем цвета – списки positive и negative внутри | |
# если положительно – красный, если отрицательно – черный, иначе – серый | |
def my_color_func(word, font_size, position, orientation, random_state=None, | |
**kwargs): | |
positive = ['managed', 'good', 'up'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# импортируем библиотеки | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
# создаем объект типа figure | |
# figure – контейнер для графика, как область | |
# в документе для картинки, к которой можно дописать | |
# заголовок графика, добавить оси и прочее |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import requests | |
from bs4 import BeautifulSoup | |
# ссылка на результаты выборов 2016 | |
# Бурятия, данные по одной ТИК (Баргузинская) | |
# один столбец – один УИК + | |
# данные по всему ТИК в самом первом столбце | |
html_with_data = "http://www.buriat.vybory.izbirkom.ru/region/region/buriat?action=show&root=32000008&tvd=2032000653530&vrn=100100067795849®ion=4&global=true&sub_region=4&prver=0&pronetvd=0&vibid=2032000653530&type=464" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import dash | |
import dash_core_components as dcc | |
import dash_html_components as html | |
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] | |
app = dash.Dash(__name__, external_stylesheets=external_stylesheets) | |
app.layout = html.Div(children=[ |