<jupyter_start><jupyter_text>Библиотека PandasКогда и зачем использоватьРежим презентации jupyter nbconvert my_script.ipynb --to slides --post servehttps://medium.com/@mjspeck/presenting-code-using-jupyter-notebook-slides-a8a3c3b59d67<jupyter_code># запуск презентации
!/Users/kbashevoy/anaconda3/bin/jupyter nbconvert Python_10_pandas_presentation_mode.ipynb --to slides --post serve
import pandas as pd
# https://grouplens.org/datasets/movielens/

ratings = pd.read_csv('ml-latest/ratings.csv')
ratings.head()
ratings.info()
# сколько фильмов в коллекции
len(ratings.movieId.unique())
%%time

# топ пользователей по количеству оценок
ratings.groupby('userId').count().sort_values('movieId', ascending=False).head()<jupyter_output>CPU times: user 1.05 s, sys: 693 ms, total: 1.74 s
Wall time: 1.83 s<jupyter_text>Lifetime<jupyter_code>ratings_grouped = ratings.groupby('userId').agg([min, max])
ratings_grouped.head()
ratings_grouped['diff'] = ratings_grouped['timestamp']['max'] - ratings_grouped['timestamp']['min']
ratings_grouped.head()
ratings_grouped['diff'].mean() / 24 / 3600
%%time

ratings = pd.read_csv('ml-latest/ratings.csv')
ratings_grouped = ratings.groupby('userId').agg([min, max])
ratings_grouped['diff'] = ratings_grouped['timestamp']['max'] - ratings_grouped['timestamp']['min']

ratings_grouped['diff'].mean() / 24 / 3600<jupyter_output>CPU times: user 14.3 s, sys: 2.41 s, total: 16.7 s
Wall time: 18 s<jupyter_text>JOIN как в SQL<jupyter_code>movies = pd.read_csv('ml-latest/movies.csv')
movies.head()
joined = ratings.merge(movies, on='movieId', how='left')
joined.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15436654366543665, 'fraction_numerical': 0.027675276752767528, 'mean_word_length': 7.135, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '431883', 'license': 'BSD-4-Clause-UC', 'n_tokens_mistral': 661, 'n_tokens_neox': 637, 'n_words': 104, 'path': '.ipynb_checkpoints/Python_10_pandas_presentation_mode-checkpoint.ipynb', 'repo_name': 'mila-khripunova/PYDA-15_WA-50_M', 'size': '1626'}