# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import numpy as np
import pandas as pd

df1 = pd.DataFrame(np.random.randn(5,5),['r1', 'r2', 'r3', 'r4', 'r5'],['c1', 'c2', 'c3', 'c4', 'c5'])
df1

df2 = pd.DataFrame({
    'cars':['Ford', 'BMW', 'Fiat'],
    'color': ['Red', 'White', 'Black'],
    'model': ['Figo', 'i3', 'Spider']
    }, index=[1,2,3])
df2

df2.drop(columns=['cars'], axis=0)

series1=df2['color']
series1.unique()

series1.value_counts()

df2[(df2['cars']!='Ford')  & (df2['model']!='i3')]

print(df1.mean())
print('')
df1.min()

df1[df1>0]

# +
# if some series has multiple of the same value then we can group all the unique entries together
mydict = {
  'customer': ['Customer 1', 'Customer 1', 'Customer2', 'Customer2', 'Customer3', 'Customer3'],   
  'product': [1.1,2.1,3.8,4.2,5.5,6.9],
  'product2': [8.2,9.1,11.1,5.2,44.66, 983]
}

df6 = pd.DataFrame(mydict, index=['Purchase 1', 'Purchase 2', 'Purchase 3', 'Purchase 4', 'Purchase 5', 'Purchase 6'])
df6
# -

grouped = df6.groupby('customer')
print(grouped)

grouped.describe()

grouped.mean()

grouped.std()

l1 = [1,2,3]
l2 = [4,5,6]
l1 + l2

l1 = [2.0001, 3.908, 4.56]
sum(l1)

l1 = [9, 7, 8, 1, 5]
l1.sort(reverse = True)
l1

# +
l1 = [1,2,3]
l2 = [4,5,6]
l3 = [7,8,9]

def sum3(a,b,c):
    d=a+b+c
    return sum(d)

sum3(l1,l2,l3)
# -

f = lambda x,y,z: x*y/z*z
f(1, 5, 78)

squares = [x**2 for x in range(10)]
print(squares)

set = [i for i in range(1,100) if i%2 == 0] 
print(set)

sentence = 'great learning is a great platform to learn about data science as it has great faculty and content.'
count = [len(i) for i in sentence.split()]
print(count)

np.identity(2)

np.array([[9,8,7],[6,5,4],[3,2,1]])

np.arange(start = 9, stop = 0, step = -1).reshape(3,3)

d1 = np.array([[9,8,7],[6,5,4],[3,2,1]])
d1 + 1

n6 = np.matrix([[ 1, 4, 9, 121, 144, 169], 
[ 16, 25, 36, 196, 225, 256], [ 49, 64, 81, 289, 324, 361]])
np.mean(n6)

n1 = np.matrix([[121, 144, 169], [196, 225, 256], [ 289, 324, 361]])
n2 = np.matrix([[ 1, 4, 9], [ 1, 5, 4], [ 9, 4, 8]])
np.dot(n1,n2)

np.arange(20)[2:7]

np.arange(20)[0::9] 

p = np.arange(20)
p[::-1]

np.matrix([[ 1, 4, 9], [ 1, 5, 4], [ 9, 4, 8]])[::-1]

mat = np.matrix([[ 1, 4, 9], [ 1, 5, 4], [ 9, 4, 8]])
print(mat[::-1])
print('')
mat.T

import numpy as np
demo_arr = np.arange(0,10)
demo_arr

demo_arr < 3

demo_arr[demo_arr < 6]

demo_matrix = np.array([[13,35,74,48],[23,37,37,38],[73,39,93,39]])
demo_matrix[:,(1,2)]

test_arr = [10,11.5,12,13.5,14,15]
test_arr[2:3]

list_l = [[12,34,55],[66,45,77],[45,77,88]]
np.array(list_l)

import pandas as pd
score = [10,15,20,25]
pd.Series(data=score,index=['a','b','c','d'])

df = pd.DataFrame(np.arange(12).reshape(3, 4), columns=['A', 'B', 'C', 'D'])
newCol = ["a", "b", "c"]
df['Alphabets']=newCol
df

np.arange(0,22,6)

da = np.arange(10,21)
ss = da[0:7]
ss[:] = 101
ss

flowers=pd.Series([2,3,5,4], index=['lily', 'rose', 'daisy', 'lotus'])
flowers['daisy']

s1=pd.Series(['a','b'])
s2=pd.Series(['c','d'])
pd.concat([s1,s2])

# # MLS Exersice

# Reading datasets by using read_csv from pandas package
ratingsDF = pd.read_csv("./data/ratings.csv")
movieDF = pd.read_csv("./data/movie.csv")
userDF = pd.read_csv("./data/user.csv")


ratingsDF.head(5)

movieDF.tail(5)

userDF.head(5)

ratingsDF.shape

userDF.shape

movieDF.shape

ratingsDF.dtypes

userDF.dtypes

movieDF.dtypes

ratingsDF.describe()

userDF.describe()

movieDF.describe()

movieDF.isna()

movieDF.isna().sum()

movieDF.columns

movieDF[[ 'Action',
       'Adventure', 'Animation', 'Childrens', 'Comedy', 'Crime', 'Documentary',
       'Drama', 'Fantasy', 'Film-Noir', 'Horror', 'Musical', 'Mystery',
       'Romance', 'Sci-Fi', 'Thriller', 'War', 'Western']].sum()

movieDF.loc[:,'Action':'Western'].sum()

# Sorting the movies across genres
number = movieDF.loc[:,'Action':'Western'].sum()
number.sort_values(ascending = False)

# +
# Find the movies that have more than one genre

new_mov_DF = movieDF[['movie id', 'movie title']].copy()
new_mov_DF['genre count'] = movieDF.loc[:,'Action':'Western'].sum(axis=1)
new_mov_DF
# -

# Filtering movies that have more than 1 genre
new_mov_DF[new_mov_DF['genre count'] > 1].reset_index()

# Find the top 25 movies according to average ratings such that each movie has number of ratings more than 100
ratingsDF['count'] = ratingsDF.groupby(['movie id'])['rating'].count()
ratingsGr100DF = ratingsDF[ratingsDF['count'] > 100].reset_index(drop = True)
ratingsGr100DF.





StarcoderdataJupyterScriptsDedupFiltered