<jupyter_start><jupyter_text>Data Transformations<jupyter_code>import pandas as pd
import numpy as np
%matplotlib inline
amzn = pd.read_excel('AMZN.xlsx')
amzn.head()
#amzn.drop('Adj Close', axis=1, inplace=True)
amzn = amzn.round(2)
amzn.head()
amzn['Change'] = np.log(amzn.Close).diff()
amzn['Volatility'] = amzn.Change.rolling(21).std()
amzn = amzn[21:]
amzn.head()
amzn['Exp Change'] = (amzn.Close * amzn.Volatility).shift(1)
amzn['Actual Change'] =amzn.Close - amzn.Close.shift(1)
amzn = amzn[1:]
amzn.head()
amzn['Magnitude'] = amzn['Actual Change'] / amzn['Exp Change']
amzn.head()
amzn.Magnitude.plot(kind='hist', bins=50)
amzn[amzn.Magnitude > 5]
amzn.to_excel('AMZN_NEW.xlsx', sheet_name='data')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19047619047619047, 'fraction_numerical': 0.0163265306122449, 'mean_word_length': 7.087912087912088, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '463791', 'license': 'MIT', 'n_tokens_mistral': 326, 'n_tokens_neox': 311, 'n_words': 51, 'path': 'Section 5/5.4-Data_transformations.ipynb', 'repo_name': 'PacktPublishing/Pandas-and-NumPy-Tips-Trick-and-Techniques', 'size': '735'}