
#TASK ONE
import numpy as np 

np.random.seed(100)
arr = np.random.randint(1,11,size=(6, 10))
arr

#define function to count values row wise
def rowwise_count_array(myarray):
# counts of the numbers in each rows
    counted_num = [np.unique(myrow, return_counts=True) for myrow in myarray]

# counts of values row wise
    return([[int(x[y==i]) if i in y else 0 for i in np.unique(myarray)] for y, x in counted_num])

# print the output
print(np.arange(1,11))
rowwise_count_array(arr)

#%%%%%%%%%%%%

#TASK TWO
import pandas as pd
# reading input from csv file
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/Cars93_miss.csv', usecols=[0,1,2,3,5])

#Replace NaNs with ‘missing’ in columns 'Manufacturer', 'Model' and 'Type'
df[['Manufacturer', 'Model', 'Type']] = df[['Manufacturer', 'Model', 'Type']].fillna('missing')

#create a index as a combination of these three columns
df.index = df.Manufacturer + '_' + df.Model + '_' + df.Type
print(df[['Manufacturer', 'Model', 'Type', 'Min.Price', 'Max.Price']])
# check if the index is a primary key
print(df.index.is_unique)

bf410e6cd4456e5d972bab69ec45e8c3cea45d2c
<mask token>


def rowwise_count_array(myarray):
    counted_num = [np.unique(myrow, return_counts=True) for myrow in myarray]
    return [[(int(x[y == i]) if i in y else 0) for i in np.unique(myarray)] for
        y, x in counted_num]


<mask token>

<mask token>
np.random.seed(100)
<mask token>
arr


def rowwise_count_array(myarray):
    counted_num = [np.unique(myrow, return_counts=True) for myrow in myarray]
    return [[(int(x[y == i]) if i in y else 0) for i in np.unique(myarray)] for
        y, x in counted_num]


print(np.arange(1, 11))
rowwise_count_array(arr)
<mask token>
print(df[['Manufacturer', 'Model', 'Type', 'Min.Price', 'Max.Price']])
print(df.index.is_unique)

<mask token>
np.random.seed(100)
arr = np.random.randint(1, 11, size=(6, 10))
arr


def rowwise_count_array(myarray):
    counted_num = [np.unique(myrow, return_counts=True) for myrow in myarray]
    return [[(int(x[y == i]) if i in y else 0) for i in np.unique(myarray)] for
        y, x in counted_num]


print(np.arange(1, 11))
rowwise_count_array(arr)
<mask token>
df = pd.read_csv(
    'https://raw.githubusercontent.com/selva86/datasets/master/Cars93_miss.csv'
    , usecols=[0, 1, 2, 3, 5])
df[['Manufacturer', 'Model', 'Type']] = df[['Manufacturer', 'Model', 'Type']
    ].fillna('missing')
df.index = df.Manufacturer + '_' + df.Model + '_' + df.Type
print(df[['Manufacturer', 'Model', 'Type', 'Min.Price', 'Max.Price']])
print(df.index.is_unique)

import numpy as np
np.random.seed(100)
arr = np.random.randint(1, 11, size=(6, 10))
arr


def rowwise_count_array(myarray):
    counted_num = [np.unique(myrow, return_counts=True) for myrow in myarray]
    return [[(int(x[y == i]) if i in y else 0) for i in np.unique(myarray)] for
        y, x in counted_num]


print(np.arange(1, 11))
rowwise_count_array(arr)
import pandas as pd
df = pd.read_csv(
    'https://raw.githubusercontent.com/selva86/datasets/master/Cars93_miss.csv'
    , usecols=[0, 1, 2, 3, 5])
df[['Manufacturer', 'Model', 'Type']] = df[['Manufacturer', 'Model', 'Type']
    ].fillna('missing')
df.index = df.Manufacturer + '_' + df.Model + '_' + df.Type
print(df[['Manufacturer', 'Model', 'Type', 'Min.Price', 'Max.Price']])
print(df.index.is_unique)


#TASK ONE
import numpy as np 

np.random.seed(100)
arr = np.random.randint(1,11,size=(6, 10))
arr

#define function to count values row wise
def rowwise_count_array(myarray):
# counts of the numbers in each rows
    counted_num = [np.unique(myrow, return_counts=True) for myrow in myarray]

# counts of values row wise
    return([[int(x[y==i]) if i in y else 0 for i in np.unique(myarray)] for y, x in counted_num])

# print the output
print(np.arange(1,11))
rowwise_count_array(arr)

#%%%%%%%%%%%%

#TASK TWO
import pandas as pd
# reading input from csv file
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/Cars93_miss.csv', usecols=[0,1,2,3,5])

#Replace NaNs with ‘missing’ in columns 'Manufacturer', 'Model' and 'Type'
df[['Manufacturer', 'Model', 'Type']] = df[['Manufacturer', 'Model', 'Type']].fillna('missing')

#create a index as a combination of these three columns
df.index = df.Manufacturer + '_' + df.Model + '_' + df.Type
print(df[['Manufacturer', 'Model', 'Type', 'Min.Price', 'Max.Price']])
# check if the index is a primary key
print(df.index.is_unique)
