Data Science Python|Nimisha|Apr 29 May 17

Discussion in 'Big Data and Analytics' started by Nimisha Pandey, May 1, 2019.

  1. Nimisha Pandey

    Nimisha Pandey Active Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    33
    Likes Received:
    10
    Weekday batch...
     
    #1
  2. Nimisha Pandey

    Nimisha Pandey Active Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    33
    Likes Received:
    10
    create a code:
    1. accepts Name and choice (Rock/Paper/scissor) of 2 players
    2. find out who wins
    3. Print a celebratory message along with the name of the player who won
    Part 2:
    1. create a code for the game but final result should be best of three
    2. create a code for best of user inputted times
    3. keep on playig till its a draw, find out who won ...?
     
    #2
  3. Nimisha Pandey

    Nimisha Pandey Active Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    33
    Likes Received:
    10
    # Prime Numbers
    # whether a number is prime or not
    # create a list with all prime numbers between 2000 and 3000
    # create a list of first 30 prime numbers
     
    #3
  4. Nimisha Pandey

    Nimisha Pandey Active Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    33
    Likes Received:
    10
    # rock breaks scissor --> wins over
    # paper covers rocks --> papaer wins
    # scissor cuts paper ---> scissor wins
     
    #4
  5. vijayaraghavan_3

    Alumni

    Joined:
    Feb 12, 2019
    Messages:
    6
    Likes Received:
    2
    Dear All,

    I have tried part 1 of the exercise and below is my code. It will prompt for the player names and choices but it will prompt for the choices until one of the player wins the game/one of the player input value is invalid (other than rock/scissor/paper).

    Note: Currently below code accepts NULL value for player names, need to include condition to check whether the name contains NULL/SPACE/NUMBERS. I will include this condition when i post part2 exercise.

    Please go through the code and share your observations.

    -------------------------PART 1 exercise---------------------------------------------------------
    # create a code:
    # 1. accepts Name and choice (Rock/Paper/scissor) of 2 players
    # 2. find out who wins
    # 3. Print a celebratory message along with the name of the player who won

    a = input ( "Player1, enter your name - " )
    b = input ( "Player1, enter your choice (rock,paper,scissor) " )

    c = input ( "Player2, enter your name - " )
    d = input ( "Player2, enter your choice (rock,paper,scissor) " )

    l = ["rock", "paper", "scissor"]
    game_end = False
    while game_end == False:
    if b.lower () in l and d.lower () in l:
    if (b == 'rock' and d == 'scissor') or (b == 'paper' and d == 'rock') or (b == 'scissor' and d == 'paper'):
    print ( a, " won the game!!" )
    game_end = True
    elif (d == 'rock' and b == 'scissor') or (d == 'paper' and b == 'rock') or (d == 'scissor' and b == 'paper'):
    print ( c, " won the game!!" )
    game_end = True
    else:
    b = input ( "Player1, enter your choice again - (rock,paper,scissor) " )
    d = input ( "Player2, enter your choice again - (rock,paper,scissor) " )
    elif b.lower () not in l and d.lower () not in l:
    print ( "Player 1 & 2 enter valid choice" )
    b = input ( "Player1, enter your choice again - (rock,paper,scissor) " )
    d = input ( "Player2, enter your choice again - (rock,paper,scissor) " )
    elif b.lower () not in l:
    print ( "Player 1,enter valid choice" )
    b = input ( "Player1, enter your choice again - (rock,paper,scissor) " )
    elif d.lower () not in l:
    print ( "Player 2,enter valid choice" )
    d = input ( "Player2, enter your choice again - (rock,paper,scissor) " )
     
    #5
    Nimisha Pandey likes this.
  6. ramya_69

    ramya_69 Member

    Joined:
    Mar 29, 2019
    Messages:
    7
    Likes Received:
    2
    name1= input("Name of the first player: ")
    name2=input("Name of the second player:")
    choice1=input("choice of first player :Rock/Paper/Scissor::")
    choice2=input("choice of second player:Rock/Paper/Scissor::")
    #rock breaks scissor -->rock wins over
    # paper covers rocks --> paper wins
    # scissor cuts paper ---> scissor wins
    if (choice1=='Rock' and choice2=='Scissor') or (choice1=='Paper' and choice2=='Rock') or (choice1=='Scissor' and choice2=='Paper'):
    print("Congratulations to", name1)

    elif(choice1=='Rock' and choice2=='Paper') or (choice1=='Paper' and choice2=='Scissor') or (choice1=='Scissor' and choice2=='Rock'):
    print("Congratulations to", name2)
    else:
    print("Its a DRAW:")

    o/p-------------------
    Name of the first player: Ramya
    Name of the second player:Om
    choice of first player :Rock/Paper/Scissor::Rock
    choice of second player:Rock/Paper/Scissor::paper
    Congratulations to Om
    #Finally i got the O/P
     
    #6
    Nimisha Pandey likes this.
  7. Alekya_1

    Alekya_1 Member

    Joined:
    Feb 5, 2019
    Messages:
    4
    Likes Received:
    2
    can any one please share todays class google drive link
     
    #7
  8. vijayaraghavan_3

    Alumni

    Joined:
    Feb 12, 2019
    Messages:
    6
    Likes Received:
    2
    Dear All,

    I have posted code to find the prime numbers. Please check below and share your observations.

    # program to find whether given number is prime number or not
    a = int(input ( "Enter a number - " ))

    if (a >1):
    for i in range(2,a):
    if a%i ==0:
    print("{} is not a prime number ({} times {} is {})". format(a,i, a//i,a))
    break
    else:
    print ( '{} is a prime number' .format(a))
    break
    else:
    print ( 'Enter a number more than 1' )


    # Program will prompt the user to enter 2 number and display the prime numbers between given numbers
    a = int ( input ( "Enter first number: " ) )
    b = int ( input ( "Enter second number: " ) )

    cnt = 0
    c = 0
    ls = []
    prime_number_flag = "N"
    if a > 1 and b > 1 and a < b:
    # print("test")
    # if a==b:
    # c=b
    # else:
    c = b + 1
    for i in range ( a, c ):
    prime_number_flag = "N"
    for j in range ( 2, i ):
    if (i % j == 0):
    prime_number_flag = "Y"
    break
    if i==2 or prime_number_flag == 'N':
    cnt = cnt + 1
    ls.append ( i )
    elif b < 0 or a < 0:
    print ( "Enter positive numbers" )
    elif b < a:
    print ( "Second number should be greater than first number" )
    elif a==1 or b==1 or a==0 or b==0:
    print ( "Enter a number greater than 1" )
    else:
    print ( "Both numbers are same, please enter different number" )

    if cnt > 0:
    print ( '{} prime number between {} and {}'.format ( cnt, a, b ) )
    print ( ls )
     
    #8
    Nimisha Pandey likes this.
  9. Karima SADAT

    Karima SADAT Member

    Joined:
    Feb 15, 2019
    Messages:
    4
    Likes Received:
    2
    #9
  10. Karima SADAT

    Karima SADAT Member

    Joined:
    Feb 15, 2019
    Messages:
    4
    Likes Received:
    2
    Dear all,
    Attached my code for prime numbers and rock/scissor/paper (part 1 and 3rd question of part 2) assignment.
     

    Attached Files:

    #10
    Nimisha Pandey likes this.
  11. Vikash Boyina

    Vikash Boyina New Member

    Joined:
    Apr 19, 2019
    Messages:
    1
    Likes Received:
    0
    You can have it over in Recordings section.
     
    #11
  12. _35952

    _35952 New Member

    Joined:
    Jul 30, 2018
    Messages:
    1
    Likes Received:
    1

    import math
    def is_prime(num):
    a = 0
    if num <=1:
    # print("The numbers less than or equal to 1 are not prime !!!")
    return False
    elif num == 2 or num == 3:
    # print("{} is prime".format(num))
    return True
    elif num%2 == 0:
    # print("{} is not prime as it is divisible by 2")
    return False
    elif (num + 1)%6 == 0 or (num - 1)%6 == 0:
    b = int(math.sqrt(num) + 1)
    for a in range (3,(b+1)):
    if num%a == 0:
    # print("{} is not prime, it is divisible by {} ".format(num,a))
    return False
    break
    else:
    if (a == b):
    # print("{} is a prime number".format(num, a))
    return True
    break
    else:
    continue
    else:
    # print("Sorry....{} is not a prime number".format(num))
    return False


    is_prime(1067)


    for i in range (2000,3000):
    if is_prime(i):
    print("{} is a prime number".format(i))
     
    #12
    Nimisha Pandey likes this.
  13. Alekya_1

    Alekya_1 Member

    Joined:
    Feb 5, 2019
    Messages:
    4
    Likes Received:
    2
    # Python program to check if given number is prime or not
    num = int(input("enter any any number"))
    # If given number is greater than 1
    if num > 1:
    for i in range(2, num//2):
    if (num % i) == 0:
    print(num, "is not a prime number")
    break
    else:
    print(num, "is a prime number")
    else:
    print(num, "is not a prime number")

    Output:

    enter any any number21
    21 is a prime number
    21 is not a prime number
     
    #13
    Nimisha Pandey likes this.
  14. Alekya_1

    Alekya_1 Member

    Joined:
    Feb 5, 2019
    Messages:
    4
    Likes Received:
    2
    # Python Program to print Prime Numbers from 2000 to 3000

    minimum = int(input("enter the minimum value: "))
    maximum = int(input("enter the maximum value: "))
    for num_1 in range (minimum , maximum+1):
    count = 0
    for i in range(2,(num_1//2 + 1)):
    if (num_1 % i) == 0:
    count = count+1
    break
    if (count == 0 and num_1 != 1):
    print(" %d" %num_1, end = ' ')

    Output:
    enter the minimum value: 2000
    enter the maximum value: 3000
    2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999
     
    #14
    Nimisha Pandey likes this.
  15. _51466

    _51466 Member

    Joined:
    Dec 10, 2018
    Messages:
    2
    Likes Received:
    1
    # Whether a number is prime number or not
    def is_prime_number(x):
    if x >= 2:
    for y in range(2,x):
    if not ( x % y ):
    return False
    else:
    return False
    return True


    I=(int(input("How many numbers you wish to check: ")))

    if (is_prime_number(I)):
    print(I," is a prime number")
    else:
    print(I," is not a prime number")



    # list of prime numbers between 2000 and 3000

    prime_numbers = []

    def is_prime_number(x):
    if x >= 2:
    for y in range(2,x):
    if not ( x % y ):
    return False
    else:
    return False
    return True

    i=2000
    while i<3000:
    if is_prime_number(i):
    prime_numbers.append(i)
    i += 1
    else:
    i += 1
    print(prime_numbers)


    # List of first 30 prime Numbers
    prime_numbers = []

    def is_prime_number(x):
    if x >= 2:
    for y in range(2,x):
    if not ( x % y ):
    return False
    else:
    return False
    return True

    i=2
    while len(prime_numbers)<30:
    if is_prime_number(i):
    prime_numbers.append(i)
    i += 1
    else:
    i += 1


    print(prime_numbers)
     
    #15
    Nimisha Pandey likes this.
  16. _51466

    _51466 Member

    Joined:
    Dec 10, 2018
    Messages:
    2
    Likes Received:
    1

    #create a code:
    #1. accepts Name and choice (Rock/Paper/scissor) of 2 players
    #2. find out who wins
    #3. Print a celebratory message along with the name of the player who won


    # find who won
    def checkWinner(userChoice1,userChoice2):
    if((userChoice1 == "rock" and userChoice2 == "paper") or
    (userChoice1 == "paper" and userChoice2 == "rock")):
    return "paper"

    elif((userChoice1 == "rock" and userChoice2 == "scissor" ) or
    (userChoice1 == "scissor" and userChoice2 == "rock")):
    return "rock"
    else:
    return "scissor"


    user1 = input("Enter First Users Name: ")

    user2 = input("Enter Second Users Name: ")

    print("Enter choice of first player \n Rock \n paper \n scissor \n")

    choice1 = input("Select first user choice: ").lower()

    choice2 = input("Select second user choice: ").lower()

    result = checkWinner(choice1,choice2)

    # Printing the celebration message
    if choice1 == choice2:
    print("<== Its a draw ==>")
    elif result == choice1:
    print("<== ",user1," wins ==>")
    else:
    print("<== ",user2," wins ==>")


    #best of 3

    # find who won
    def checkWinner(userChoice1,userChoice2):
    if((userChoice1 == "rock" and userChoice2 == "paper") or
    (userChoice1 == "paper" and userChoice2 == "rock")):
    return "paper"

    elif((userChoice1 == "rock" and userChoice2 == "scissor" ) or
    (userChoice1 == "scissor" and userChoice2 == "rock")):
    return "rock"
    else:
    return "scissor"


    user1 = input("Enter First Users Name: ")

    user2 = input("Enter Second Users Name: ")

    wins1=0

    wins2=0

    print("Enter choice of first player \n Rock \n paper \n scissor \n")

    for i in range(3):
    print("Round ",i+1)

    choice1 = input("Select first user choice: ").lower()

    choice2 = input("Select second user choice: ").lower()

    result = checkWinner(choice1,choice2)

    # Printing the celebration message
    if choice2 == choice1 :
    print("<== this round is a draw ==>")
    elif result == choice1 :
    wins1+=1
    print("<== ",user1," wins this round ==>")
    else:
    wins2+=1
    print("<== ",user2," wins this round ==>")

    if wins1 > wins2 :
    print("<== ",user1," wins ==>")
    elif wins1 == wins2 :
    print("<== Its a draw ==>")
    else:
    print("<== ",user2," wins ==>")

    # create a code for best of user inputted times
    # find who won
    def checkWinner(userChoice1,userChoice2):
    if((userChoice1 == "rock" and userChoice2 == "paper") or
    (userChoice1 == "paper" and userChoice2 == "rock")):
    return "paper"

    elif((userChoice1 == "rock" and userChoice2 == "scissor" ) or
    (userChoice1 == "scissor" and userChoice2 == "rock")):
    return "rock"
    else:
    return "scissor"


    user1 = input("Enter First Users Name: ")

    user2 = input("Enter Second Users Name: ")

    wins1=0

    wins2=0

    rounds = int(input("Enter number of rounds you want to play: "))

    print("Enter choice of players \n Rock \n paper \n scissor \n")

    for i in range(rounds):
    print("Round ",i+1)

    choice1 = input("Select first user choice: ").lower()

    choice2 = input("Select second user choice: ").lower()

    result = checkWinner(choice1,choice2)

    # Printing the celebration message
    if choice2 == choice1 :
    print("<== this round is a draw ==>")
    elif result == choice1 :
    wins1+=1
    print("<== ",user1," wins this round ==>")
    else:
    wins2+=1
    print("<== ",user2," wins this round ==>")

    if wins1 > wins2 :
    print("<== ",user1," wins ==>")
    elif wins1 == wins2 :
    print("<== Its a draw ==>")
    else:
    print("<== ",user2," wins ==>")

    # keep on playig till its a draw, find out who won ...?
    # find who won
    def checkWinner(userChoice1,userChoice2):
    if((userChoice1 == "rock" and userChoice2 == "paper") or
    (userChoice1 == "paper" and userChoice2 == "rock")):
    return "paper"

    elif((userChoice1 == "rock" and userChoice2 == "scissor" ) or
    (userChoice1 == "scissor" and userChoice2 == "rock")):
    return "rock"
    else:
    return "scissor"


    user1 = input("Enter First Users Name: ")

    user2 = input("Enter Second Users Name: ")

    wins1=0

    wins2=0

    i=1

    print("Enter choice of players \n Rock \n paper \n scissor \n")

    while True:
    print("Round ",i)

    choice1 = input("Select first user choice: ").lower()

    choice2 = input("Select second user choice: ").lower()

    result = checkWinner(choice1,choice2)

    # Printing the celebration message
    if choice2 == choice1 :
    print("<== this round is a draw ==>")
    break;
    elif result == choice1 :
    wins1+=1
    print("<== ",user1," wins this round ==>")
    else:
    wins2+=1
    print("<== ",user2," wins this round ==>")
    i += 1

    if wins1 > wins2 :
    print("<== ",user1," wins ==>")
    elif wins1 == wins2 :
    print("<== Its a draw ==>")
    else:
    print("<== ",user2," wins ==>")
     
    #16
  17. Mahesh Pillala

    Joined:
    Mar 29, 2019
    Messages:
    2
    Likes Received:
    1
    #1. whether a number is prime or not
    n1= int(input('Enter a number: '))
    #default flag set to True as Prime number
    flag ='True'
    for i in range(2,n1-1):
    if(n1%i)==0:
    #flag set to false as it is divisible
    flag = 'False'
    break;
    if(flag =='True'):
    print('It is a prime number')
    else:
    print ('It is not a prime number')

    #2. create a list with all prime numbers between 2000 and 3000
    print('Prime numbers between 2000 and 3000')
    i=2000
    while i<=3000:
    flag ='True'
    for j in range(2,i-1):
    if(i%j)==0:
    flag = 'False'
    break;
    if(flag =='True'):
    print(j)
    i= i+1

    #3. create a list of first 30 prime numbers
    print('List of first 30 prime numbers')
    list_1=[]
    i=2000
    #Counter flag set to 1
    cnt =1;
    while i<=3000:
    flag ='True'
    for j in range(2,i-1):
    if((i%j)==0 and cnt<=30):
    flag = 'False'
    break;
    if(flag =='True'):
    #print(j)
    if(cnt<=30):
    list_1.append(j)
    cnt =cnt+1
    i= i+1
    print(list_1)
     
    #17
    Nimisha Pandey likes this.
  18. Mahesh Pillala

    Joined:
    Mar 29, 2019
    Messages:
    2
    Likes Received:
    1
     
    #18
  19. Bhanu Kiran Maddela

    Joined:
    Mar 31, 2019
    Messages:
    3
    Likes Received:
    0
    import random
    while True:
    print("Enter choice \n 1. Rock \n 2. paper \n 3. scissor \n")
    choice = int(input("User turn: "))
    while choice > 3 or choice < 1:
    choice = int(input("enter valid input: "))
    if choice == 1:
    choice_name = 'Rock'
    elif choice == 2:
    choice_name = 'paper'
    else:
    choice_name = 'scissor'
    print("user choice is: " + choice_name)
    print("\nNow its computer turn.......")
    comp_choice = random.randint(1, 3)
    while comp_choice == choice:
    comp_choice = random.randint(1, 3)
    if comp_choice == 1:
    comp_choice_name = 'Rock'
    elif comp_choice == 2:
    comp_choice_name = 'paper'
    else:
    comp_choice_name = 'scissor'
    print("Computer choice is: " + comp_choice_name)
    print(choice_name + " V/s " + comp_choice_name)
    if((choice == 1 and comp_choice == 2) or
    (choice == 2 and comp_choice ==1 )):
    print("paper wins => ", end = "")
    result = "paper"
    elif((choice == 1 and comp_choice == 3) or
    (choice == 3 and comp_choice == 1)):
    print("Rock wins =>", end = "")
    result = "Rock"
    else:
    print("scissor wins =>", end = "")
    result = "scissor"
    if result == choice_name:
    print("<== User wins ==>")
    else:
    print("<== Computer wins ==>")
    print("Do you want to play again? (Y/N)")
    ans = input()
    if ans == 'n' or ans == 'N':
    break
    print("\nThanks for playing")
     
    #19
  20. Bhanu Kiran Maddela

    Joined:
    Mar 31, 2019
    Messages:
    3
    Likes Received:
    0
    #To check weather a number is prime or not#
    number=int(input("enter a number"))
    for i in range(2,number):
    if i%2==0:
    print("not a prime number")
    break
    else:
    print("prime number")
     
    #20
  21. Bhanu Kiran Maddela

    Joined:
    Mar 31, 2019
    Messages:
    3
    Likes Received:
    0
    #program to print the prime number between2000-3000 #
    for i in range(2000,3000):
    for j in range(2,i):
    if i%j==0:
    break
    else:
    print(i)
     
    #21
  22. Alekya_1

    Alekya_1 Member

    Joined:
    Feb 5, 2019
    Messages:
    4
    Likes Received:
    2
    #22
  23. Nimisha Pandey

    Nimisha Pandey Active Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    33
    Likes Received:
    10
    1. Replace team names with initials of team names
    2. Find out the teams for whom the matches resulted in a tie
    3. Find out the no. of matches played in a city (for all cities)
    4. For each city find out the team which won maximum matches in that city and how didi they win --> win by runs or win by wicket ----> average without decimal points
    5. For every winner team find out who got the max titles for man of the match
    6. Which team lost the maximum no of matches in year 2017.
    7. For each team which was a more favorable toss decision
     
    #23
  24. ramya_69

    ramya_69 Member

    Joined:
    Mar 29, 2019
    Messages:
    7
    Likes Received:
    2
    hello,
    i got the first 3....i am trying to do the rest today

    import pandas as pd
    m1=pd.read_csv('C:\Users\home\Downloads\matches.csv')
    m1
    m2=m1.loc[:,'id':'team2']
    m2.team1.replace(to_replace=({"Sunrisers Hyderabad":'S.R.H.','Mumbai Indians':'M.I.',
    'Gujarat Lions':'G.I','Delhi Daredevils':'D.D',
    'Royal Challengers Bangalore':'R.C.B','Kolkata Knight Riders':'K.K.R',
    'Rising Pune Supergiants':'R.P.S','Rising Pune Supergiants':'R.P.S.',
    'Kings XI Punjab':'K.P.'}),inplace=True)
    m2.team2.replace(to_replace=({"Sunrisers Hyderabad":'S.R.H.','Mumbai Indians':'M.I.',
    'Gujarat Lions':'G.I','Delhi Daredevils':'D.D',
    'Royal Challengers Bangalore':'R.C.B','Kolkata Knight Riders':'K.K.R',
    'Rising Pune Supergiant':'R.P.S','Rising Pune Supergiants':'R.P.S.',
    'Kings XI Punjab':'K.P.'}),inplace=True)
    m2
    --------------------------------------
    m1['result']='Winner'
    m1.loc[(m1.win_by_runs==0),'result']='Tie'
    m1
    m1[np.logical_and(np.logical_or(m1['team1'],m1['team2']),m1['result']=='Tie')]
    -----------------------------------------
    m1[np.logical_and(m1['city']=='Hyderabad',m1['result']=='Winner')]
     
    #24
    Nimisha Pandey likes this.
  25. ramya_69

    ramya_69 Member

    Joined:
    Mar 29, 2019
    Messages:
    7
    Likes Received:
    2
    To upload movie.dat file i used the following code. It got uploaded but with a warning message.
    Would you please check my code and reply me whether i did any mistake.

    import pandas as pd
    mov = pd.read_table("C:\Users\home\movies.dat")
    C:\Users\home\Anaconda2\lib\site-packages\ipykernel_launcher.py:2: FutureWarning: read_table is deprecated, use read_csv instead, passing sep='\t'.
    //////////////////
    got the o/p
    the above statement is showing the table o/p but with the above warning message
     
    #25
  26. ramya_69

    ramya_69 Member

    Joined:
    Mar 29, 2019
    Messages:
    7
    Likes Received:
    2
    data['Survived'].value_counts().plot.pie(explode = [0.0,0.1],
    autopct ='%1.2f%%',
    shadow = True,
    colormap = 'spring',
    labels = ['Dead','Alive'])


    ---------------------How to know the options from plot.pie..........means how to get help on these options....please let me know
     
    #26
  27. Karima SADAT

    Karima SADAT Member

    Joined:
    Feb 15, 2019
    Messages:
    4
    Likes Received:
    2
    Dear all,
    here is my code for the 3 first questions


    import pandas as pd
    import numpy as np
    matches = pd.read_csv('matches.csv')

    matches

    matches1=matches.copy()

    matches1.head()

    matches1.set_index('id', inplace = True)
    matches1


    Replace team names with initials of team names

    def initials(team):

    list_of_names = team.split()
    initials = ''.join(name[0] for name in list_of_names)
    return initials

    for i in matches1.index:
    matches1.loc[i,'team1'] = initials(matches1.loc[i,'team1'])
    matches1.loc[i,'team2'] = initials(matches1.loc[i,'team2'])


    matches1.head()


    Find out the teams for whom the matches resulted in a tie

    matches1.loc[matches1['result'] == 'tie'].shape

    #show all the data for teams for whom the matches resulted in a tie

    matches1[matches1['result'] == 'tie']

    #show just teams for whom the matches resulted in a tie

    matches1[['team1','team2']][matches1['result'] == 'tie']



    Find out the no. of matches played in a city (for all cities)

    matches1['city'].value_counts()
    #or
    matches1.groupby('city').agg({'city':'count'})

     
    #27
    Nimisha Pandey likes this.
  28. Karima SADAT

    Karima SADAT Member

    Joined:
    Feb 15, 2019
    Messages:
    4
    Likes Received:
    2

    Hi Ramya,

    I used this code to upload the files
    import pandas as pd
    movies = pd.read_table('movies.dat', sep = '::', index_col=0, header=None ,names=['Titles','Genres'] )
    users = pd.read_table('users.dat', sep = '::', index_col=0, header=None ,names=['UserID','Gender','Age','Occupation','Zip-code']
    ratings = pd.read_table('ratings.dat', sep = '::', index_col=0, header=None ,names=['UserID','MovieID','Rating','Timestamp'] )

    I tried your code but it's throwing an error. There are some options that you need to specify for pd.read_table like sep..
     
    #28
  29. Nimisha Pandey

    Nimisha Pandey Active Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    33
    Likes Received:
    10
    Hi Ramya ,

    As the warning is suggesting that pd.read_table is depreciating in the newer versions of Python.. so you can also use pd.read_csv but in that case you will have explicitly specify the separator... ie.:
    pd.read_csv(filepath, sep = "::")
    # separator is the character or whatever is separating the values in a table in CSV its a comma...
    in movie lens data it is :: double colon

    by default in read_csv sep = ',' and in read_table sep ='\t'

    for more information call help

    Best, Nimisha
     
    #29
  30. Nimisha Pandey

    Nimisha Pandey Active Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    33
    Likes Received:
    10
  31. ramya_69

    ramya_69 Member

    Joined:
    Mar 29, 2019
    Messages:
    7
    Likes Received:
    2
    thank u Nimisha Mam for timely help. i could get it with seperators and other options
    one more question ...
    Question 6
    A USA Today/CNN/Gallup survey of 369 working parents found 200 who said they spend too little time with their
    children because of work commitments.
    a. What is the point estimate of the proportion of the population of working parents who feel they spend too
    little time with their children because of work commitments?
    b. At 95% confidence, what is the margin of error?
    c. What is the 95% confidence interval estimate of the population proportion of working parents who feel they
    spend too little time with their children because of work commitments?

    In this question may i know how to get mean and std dev?
     
    #31
  32. ramya_69

    ramya_69 Member

    Joined:
    Mar 29, 2019
    Messages:
    7
    Likes Received:
    2
    #32
  33. vijayaraghavan_3

    Alumni

    Joined:
    Feb 12, 2019
    Messages:
    6
    Likes Received:
    2
    Hi Nimisha,

    This is regarding 'Movie lens' project.

    1) I have imported the DAT files in to variables (Movies, ratings and user) and joined the data as below. please confirm my joining is correct or not.

    mov_rat = Movies left outer join with Ratings (Reason for using left outer join - 177 ratings are not matching with Movies table due to mismatch in MovieID)

    final_data = mov_rat join with user

    2) I've created a bar plot to represent 'User Age Distribution'. Is bar plot the best way to represent age distribution or do i need to use any other plots?
    Please assist
     
    #33
  34. vijayaraghavan_3

    Alumni

    Joined:
    Feb 12, 2019
    Messages:
    6
    Likes Received:
    2
    Hi Nimisha,

    I need some clarity on below problem statement.

    'Determine the features affecting the ratings of any particular movie.'

    I am using decision tree to find out the features affecting the rating of a movie. I have below mentioned columns in both training and test data

    Movie id, User id, Rating, Occupation, Action, Adventure..... Thriller, Male, Female, 18-24,25-34, 35-44, 45-49, 50-55, 56+, Under 18

    Total columns - 31 columns (number of genres - 18; I've not mentioned all the genres above)

    Question 1 - Do i need to find out the features which are affecting the individual rating of a movie i.e 5.0,4.0,3.0,2.0,1.0 ?

    Question 2: In order to answer this question, do i need to find only features or i have to build decision tree , prune till prediction model?
     
    #34
  35. vijayaraghavan_3

    Alumni

    Joined:
    Feb 12, 2019
    Messages:
    6
    Likes Received:
    2

    --------------------------------------
    Hi Nimisha,

    In order to create a model (4th question;refer below), first i have to find out the features (3rd question;refer below) then i can test my prediction accuracy? is my understanding correct?

    3.Determine the features affecting the ratings of any particular movie
    4.Develop an appropriate model to predict the movie ratings
     
    #35
  36. ramya_69

    ramya_69 Member

    Joined:
    Mar 29, 2019
    Messages:
    7
    Likes Received:
    2
    Hi Nimisha Mam,
    Would u please post all the answers for the questions given by u so that i can cross check with mine
     
    #36

Share This Page