<jupyter_start><jupyter_text>1.1<jupyter_code>df = pd.read_csv('AMZN.csv')
df.columns = df.columns.str.replace(' ', '_')
df['Close_Price'] = df['Close_Price'].str.replace(',', '').astype(float)
df.head()<jupyter_output><empty_output><jupyter_text>1.2<jupyter_code>cp = np.array(df['Close_Price'])
cp = cp[0:90]
print('Maximum price for last 90 days: ', max(cp))
print('Minimum price for last 90 days: ', min(cp))
print('Mean price for last 90 days: ',np.mean(cp))<jupyter_output>Mean price for last 90 days:  1837.378666666667<jupyter_text>1.3<jupyter_code>df.dtypes
df['Date'] = pd.to_datetime(df['Date'])
max(df['Date']) - min(df['Date'])
df.dtypes<jupyter_output><empty_output><jupyter_text>1.4<jupyter_code>df['Month'] = pd.DatetimeIndex(df['Date']).month
df['Year'] = pd.DatetimeIndex(df['Date']).year
df.head()
ttq = df['Total_Traded_Quantity'].str.replace('M', '')
ttq = np.array(ttq.astype(float)) * 1000000
df['Total_Traded_Quantity'] = ttq
df.head()
def vwap(df):
    q = df.Total_Traded_Quantity.values
    p = df.Close_Price.values
    return df.assign(VWAP=(p * q).cumsum() / q.cumsum())

df = df.groupby([(df['Year']),(df['Month'])]).apply(vwap)
df = df.sort_values(by=['Date'], ascending=False)
df.head()<jupyter_output><empty_output><jupyter_text>1.5<jupyter_code>def avg_Price(n):
    return np.mean(np.array(df['Close_Price'])[0:n])

def Profit_Loss(n):
    cp = np.array(df['Close_Price'])
    return ((cp[n-1]-cp[0])/cp[0])*100
print('Avergae Price of last 1 week: ', avg_Price(7))
print('Avergae Price of last 2 weeks: ', avg_Price(14))
print('Avergae Price of last 1 month: ', avg_Price(30))
print('Avergae Price of last 3 months: ', avg_Price(91))
print('Avergae Price of last 6 months: ', avg_Price(182))
print('Avergae Price of last 1 year: ', avg_Price(365))
print('Profit/Loss Percentage of last 1 week: ', Profit_Loss(7))
print('Profit/Loss Percentage of last 2 weeks: ', Profit_Loss(14))
print('Profit/Loss Percentage of last 1 month: ', Profit_Loss(30))
print('Profit/Loss Percentage of last 3 months: ', Profit_Loss(91))
print('Profit/Loss Percentage of last 6 months: ', Profit_Loss(182))
print('Profit/Loss Percentage of last 1 year: ', Profit_Loss(365))<jupyter_output>Profit/Loss Percentage of last 1 week:  -0.18811981266635458
Profit/Loss Percentage of last 2 weeks:  -2.7021866822403604
Profit/Loss Percentage of last 1 month:  3.288446635743884
Profit/Loss Percentage of last 3 months:  6.771751704309343
Profit/Loss Percentage of last 6 months:  -7.890924201754286
Profit/Loss Percentage of last 1 year:  -11.49271667471558<jupyter_text>1.6<jupyter_code>df['Day_Perc_Change'] = df['Close_Price'].pct_change()*100
df['Day_Perc_Change'][0] = 0
df.head()<jupyter_output>C:\Users\Dell\anaconda3\lib\site-packages\ipykernel_launcher.py:2: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy<jupyter_text>1.7<jupyter_code>def label_race (df):
    if df['Day_Perc_Change'] >= -0.5 and df['Day_Perc_Change'] <= 0.5:
      return 'Slight or No change'
    if df['Day_Perc_Change'] >= 0.5 and df['Day_Perc_Change'] <= 1.0:
      return 'Slight positive'
    if df['Day_Perc_Change'] >= -1.0 and df['Day_Perc_Change'] <= -0.5:
      return 'Slight negative'
    if df['Day_Perc_Change'] >= 1.0 and df['Day_Perc_Change'] <= 3.0:
      return 'Positive'
    if df['Day_Perc_Change'] >= -3.0 and df['Day_Perc_Change'] <= -1.0:
      return 'Negative'
    if df['Day_Perc_Change'] >= 3.0 and df['Day_Perc_Change'] <= 7.0:
      return 'Among top gainers'
    if df['Day_Perc_Change'] >= -7.0 and df['Day_Perc_Change'] <= -3.0:
      return 'Among top losers'
    if df['Day_Perc_Change'] > 7.0:
      return 'Bull run'
    if df['Day_Perc_Change'] < -7.0:
      return 'Bear drop'
    return 'Other'

df['Trend'] = df.apply(lambda df: label_race(df), axis=1)
df.head()<jupyter_output><empty_output><jupyter_text>1.8<jupyter_code>avg = df.groupby(df['Trend'])['Total_Traded_Quantity'].mean()
med = df.groupby(df['Trend'])['Total_Traded_Quantity'].median()
print('Average of Total_Traded_Quantity: \n', avg)
print('\nMedian of Total_Traded_Quantity: \n',med)<jupyter_output>Average of Total_Traded_Quantity: 
 Trend
Among top gainers      6.445161e+06
Among top losers       7.190000e+06
Bear drop              6.420000e+06
Bull run               1.029000e+07
Negative               4.891727e+06
Positive               5.060746e+06
Slight negative        4.368082e+06
Slight or No change    4.188966e+06
Slight positive        4.620192e+06
Name: Total_Traded_Quantity, dtype: float64

Median of Total_Traded_Quantity: 
 Trend
Among top gainers       6020000.0
Among top losers        6515000.0
Bear drop               6420000.0
Bull run               10290000.0
Negative                4385000.0
Positive                4520000.0
Slight negative         3810000.0
Slight or No change     3680000.0
Slight positive         4265000.0
Name: Total_Traded_Quantity, dtype: float64<jupyter_text>1.9<jupyter_code>df.to_csv('week2.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1498062015503876, 'fraction_numerical': 0.07771317829457364, 'mean_word_length': 4.573434125269978, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '203850', 'license': 'MIT', 'n_tokens_mistral': 2271, 'n_tokens_neox': 1965, 'n_words': 405, 'path': 'Module 1.ipynb', 'repo_name': 'parth2608/Stock-Analysis', 'size': '5160'}