<jupyter_start><jupyter_text>Assignment 1<jupyter_code>#Part one of assignment 1

import numpy as np<jupyter_output><empty_output><jupyter_text>Question number 1<jupyter_code>#function to qustion number 1 in the assigment 
def calculate_hours(n_bacteria):
    count_hours=0
    while(n_bacteria<1000000):
        count_hours=count_hours+1 
        n_bacteria=n_bacteria*2
        print(count_hours,"hours:",n_bacteria,"bacteria")
        print("-----------------------------")
#testing the function to use the function call calculate_hours(with your input)  
calculate_hours(int(input()))<jupyter_output>499
1 hours: 998 bacteria
-----------------------------
2 hours: 1996 bacteria
-----------------------------
3 hours: 3992 bacteria
-----------------------------
4 hours: 7984 bacteria
-----------------------------
5 hours: 15968 bacteria
-----------------------------
6 hours: 31936 bacteria
-----------------------------
7 hours: 63872 bacteria
-----------------------------
8 hours: 127744 bacteria
-----------------------------
9 hours: 255488 bacteria
-----------------------------
10 hours: 510976 bacteria
-----------------------------
11 hours: 1021952 bacteria
-----------------------------<jupyter_text>question number 2 : A)<jupyter_code>#create arry size 1000 with randoms numbers 0-1000
x = np.random.randint(1000,size=1000)<jupyter_output><empty_output><jupyter_text>B<jupyter_code># every number that div by 3 and by 4 set it into 12
x[(x%3==0)&(x%4==0)]=12
# print x to make sure it work
x<jupyter_output><empty_output><jupyter_text>c) Convert x to a 2-dimensional array with 4 rows.<jupyter_code>x=np.reshape(x,(4,-1))
#testing the array
x[3][1]<jupyter_output><empty_output><jupyter_text>D)	Create two random arrays of integers between 1 and 100, each of length 100, x1 and x2.<jupyter_code>x1 = np.random.randint(1,100,size=100)
x2 = np.random.randint(1,100,size=100)
x1,x2<jupyter_output><empty_output><jupyter_text>F)	Find the positions of elements in x1 and x2 that match (i.e. positions where the elements in the two arrays are the same). result will contain array of the indexs that the numbers in x1 and x2 equal<jupyter_code>result = np.where(x1==x2)
result<jupyter_output><empty_output><jupyter_text>g) Find the intersection of x1 and x2, and save it to a third array, x3.<jupyter_code>x3 = np.intersect1d(x1,x2)
x3<jupyter_output><empty_output><jupyter_text>h)	Remove the intersection of x1 and x2 from both arrays, x1 and x2.<jupyter_code>x1=np.setxor1d(x1,x3)
x2=np.setxor1d(x2,x3)<jupyter_output><empty_output><jupyter_text>question 3 Write a program that will find numbers between 2000 and 3000 that are divisible by 7 but not by 5. Print all these numbers. Try to find a way to print the numbers in one line, separated by a comma.<jupyter_code># if include 3000 so its range 2000-3001 if not change 3001 to 3000
def find_div_numbers():
    for i in range(2000,3001):
         if((i%7==0)&(i%5!=0)):
            print(i,end=",")        
find_div_numbers()<jupyter_output>2002,2009,2016,2023,2037,2044,2051,2058,2072,2079,2086,2093,2107,2114,2121,2128,2142,2149,2156,2163,2177,2184,2191,2198,2212,2219,2226,2233,2247,2254,2261,2268,2282,2289,2296,2303,2317,2324,2331,2338,2352,2359,2366,2373,2387,2394,2401,2408,2422,2429,2436,2443,2457,2464,2471,2478,2492,2499,2506,2513,2527,2534,2541,2548,2562,2569,2576,2583,2597,2604,2611,2618,2632,2639,2646,2653,2667,2674,2681,2688,2702,2709,2716,2723,2737,2744,2751,2758,2772,2779,2786,2793,2807,2814,2821,2828,2842,2849,2856,2863,2877,2884,2891,2898,2912,2919,2926,2933,2947,2954,2961,2968,2982,2989,2996,<jupyter_text>Part 2 of the assignment<jupyter_code>import pandas as pd<jupyter_output><empty_output><jupyter_text>question 4 a)	Create a Panda's dataframe 20*5, with random integers between 1 to 100.<jupyter_code>df =pd.DataFrame(np.random.randint(1,100,size=(20, 5)),columns=["a","b","c","d","e"])
df<jupyter_output><empty_output><jupyter_text>b)	Multiply the second column by 2, using number index.   because we are starting to count from zero in order to multiply the second column we need to pick column number [0,1] here we change the second column by multiply of 2<jupyter_code>df.iloc[:,1]=df.iloc[:,1]*2
df<jupyter_output><empty_output><jupyter_text>c)	Give your columns names: 'col1', 'col2' and so on.<jupyter_code>df.rename(columns={"a":"col1","b":"col2","c":"col3","d":"col4","e":"col5"},inplace=True)
df<jupyter_output><empty_output><jupyter_text>d)	Multiply the third column by 3, using column names.<jupyter_code>df.loc[:,"col3"] *= 3
df<jupyter_output><empty_output><jupyter_text>e)Multiply entries with odd indices in column four by 5.<jupyter_code>df.loc[1:len(df)-1:2,"col4"]*=5
   
df
#another option is to use df.loc[1:19:2,"col4"]*=5<jupyter_output><empty_output><jupyter_text>f)	Add a column to the dataframe with NaNs.Give this column a name, 'new'.<jupyter_code>df['new']=np.nan
df<jupyter_output><empty_output><jupyter_text>g)	For each line where the third column is divisible by 5, copy the value to<jupyter_code>#the new column you created before. For lines that do no meet this criteria, 
#set the value of the new column to 3.
df['new']= df['col3'][df['col3']%5==0]  #passing the numbers that div by 5 
df['new']=df['new'].fillna(3) #changing all the Nans to 3 
df<jupyter_output><empty_output><jupyter_text>question number 5<jupyter_code>#D:\DVIR\HIT\מבוא למדעי הנתונים\Assignment 01\winequality-red
data = pd.read_csv('winequality-red.csv',sep=";")
data.head()<jupyter_output><empty_output><jupyter_text>A)	Change to precision of the density column – rounding it to 3 precision digits,<jupyter_code>format = lambda x:'%.3f' % x
data['density']=data['density'].map(format)<jupyter_output><empty_output><jupyter_text>B)	Take the first 5 rows of the data and copy into a new object.<jupyter_code>#Take the last 10 rows of the data and copy into a new object.
#Use Panda's concat to create another object with 15 rows. 
#Print out the object.
first_five_rows = data.head(5)
last_ten_rows = data.tail(10)
unit_rows = pd.concat([first_five_rows,last_ten_rows])
unit_rows<jupyter_output><empty_output><jupyter_text>c)	Find rows for which 'fixed acidity' is > 15.7 and print these out. How many are there?<jupyter_code>bigVal = data.loc[data['fixed acidity'] > 15.7]
bigVal

print('Amount = ',bigVal.shape[0]) #getting the number of rows<jupyter_output><empty_output><jupyter_text>D)	Create a function which, given a series, calculates the number of missing values. Apply the function to the columns of the data using apply.Now apply the function on the rows using apply again.<jupyter_code>#this function counts the number of nans
def numOfMissingValues(val):
    return val.isnull().sum() 
data.apply(numOfMissingValues,axis=0)
data.apply(numOfMissingValues,axis=1)<jupyter_output><empty_output><jupyter_text>E)	Write a function that converts a fraction into a percentage. Apply it using apply to the citric acid column.<jupyter_code># applying lambda to change to %
precentage = lambda x:'%.0f%%' % (100 *x)

data['citric acid']=data['citric acid'].apply(precentage)
data.head()
#f)	Print out means for the columns.
data.mean(axis = 0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16543554006968642, 'fraction_numerical': 0.10536585365853658, 'mean_word_length': 4.955186721991701, 'pattern_counts': {'":': 5, '<': 96, '<?xml version=': 0, '>': 97, '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': '24', 'dir': 'jupyter-structured-clean-dedup', 'id': '634067', 'license': 'MIT', 'n_tokens_mistral': 3034, 'n_tokens_neox': 2589, 'n_words': 645, 'path': 'Assignment 01- numpy/Assignment 1.ipynb', 'repo_name': 'dt170/Data_Science_Assigments', 'size': '7175'}