Beispiel #1
0
def show_tweets_by_month():
    '''
    앞서 작성한 함수를 이용해 월별 트윗 개수를 보여주는 그래프를 출력합니다. 
    '''

    months = range(1, 13)
    num_tweets = [len(filter_by_month(trump_tweets, month)) for month in months]
    
    plt.bar(months, num_tweets, align='center')
    plt.xticks(months, months)
    
    plt.savefig('graph.png')
    elice_utils = EliceUtils()
    elice_utils.send_image('graph.png')
from elice_utils import EliceUtils
import urllib.request
from bs4 import BeautifulSoup

elice_utils = EliceUtils()


def main():
    print("href 출력해보기")

    list_href = []

    url = "http://sports.donga.com/Enter"
    soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html.parser")

    # 반복문을 사용해 원하는 정보 range(3,23)까지 find("a")["href"] 를 사용해서
    # href 모두 수집하여 list_href에 저장

    for i in range(3, 23):
        list_href.append(
            soup.find_all("span", class_="tit")[i].find("a")["href"])

    # source = soup.find_all("span", class_="tit"):
    # for i in ragne(3, 23):
    #     link = source[i].find("a")["href"]
    #     list_href.append(link)
    print(list_href)


if __name__ == "__main__":
    main()
Beispiel #3
0
# Task 1. K-means clustering from scratch

import numpy as np
import pandas as pd
from sklearn.datasets import make_blobs
from matplotlib import pyplot as plt
from copy import deepcopy

from elice_utils import EliceUtils
eu = EliceUtils()

# Check versions
print('numpy version: ', np.__version__)
print('pandas version: ', pd.__version__)

np.random.seed(12345)

# Q1. Create a dataset (X and y) with 3 clusters usng sklearn.datasets.make_blobs
X, y = make_blobs(n_samples=800, n_features=2, centers=3, random_state=12345)


#print(X.shape,y.shape)
# Q2: define a function to calculate Euclidean distance
def dist(a, b, ax=1):
    """
    :param a: 1-D input array
    :param b: 1-D input array
    :param axis: an integer for the axis of a and b along which to compute the vector norms
    :return: Eucleadian distance (float)    
    """
    return np.linalg.norm(a - b, axis=ax)  # axis = 1 행연산
Beispiel #4
0
# I am very sorry for
    # * not obeying PEP8,
    # * abusing & spamming array comprehension instead of for-loop,
    # * using dynamic import although it is not dynamic,
    # * using __setitem__ to avoid variable-assignment limit in lambda,
        # (:= operator was possible, but that is implemented in Python 3.8)
    # * creating useless lambda function for each loop,
    # * finally, last but not least, using not-documented properties (in cs1 libraries)

# But I hope you TA guys enjoy this one-lined code.
# If you enjoyed this, please push 'Like' and 'Subscribe' button in git.nenw.dev (GitHub @HelloWorld017)
"""

# --- Your code ends here ---
########################################

download_message = '⬇ Download the result image file from the link below ⬇'
print('#' * len(download_message))
print(download_message)
sleep(0.1)

# Save your image object as a file.
image.save_as('./result.png')
# Show a download link for your result image file.
utils = EliceUtils()
utils.send_file('./result.png')

sleep(0.1)
print('#' * len(download_message))