Python for Data Science | Jan 20 | Nimisha

Discussion in 'Big Data and Analytics' started by Nimisha Pandey, Jan 20, 2020.

  1. Nimisha Pandey

    Nimisha Pandey Well-Known Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    65
    Likes Received:
    69
  2. Aravindhakshan L

    Aravindhakshan L New Member

    Joined:
    Sep 14, 2019
    Messages:
    1
    Likes Received:
    1
    #2
    Alona Sorochynska likes this.
  3. Qian (Robin) Zhang

    Joined:
    Dec 26, 2019
    Messages:
    4
    Likes Received:
    0
    Hi Nimisha,
    I tried to submit my assignment regarding the rock paper scissors game but failed. I could not upload to your google drive, nor the share folder in the lab , nor in the community ? Would you be able to advise me a proper way of submit the homework?
     
    #3
  4. AnithaSanjeevan

    AnithaSanjeevan Customer
    Customer

    Joined:
    Jan 7, 2020
    Messages:
    3
    Likes Received:
    2
    player1={}
    player1Name = input('Please enter Player1 Name : ')
    player1['Name'] = player1Name
    player1Choice = input('Please enter Player1 Choice - Rock or Paper or Scissor: ')
    player1['Choice'] = player1Choice
    player2={}
    player2Name = input('Please enter Player2 Name : ')
    player2['Name'] = player2Name
    player2Choice = input('Please enter Player2 Choice - Rock or Paper or Scissor: ')
    player2['Choice'] = player2Choice
    if (player1['Choice'].lower() == 'rock') and (player2['Choice'].lower() == 'scissor'):
    print('Winner -',player1['Name'])
    elif (player2['Choice'].lower() == 'rock') and (player1['Choice'].lower() == 'scissor'):
    print('Winner -',player2['Name'])
    elif (player1['Choice'].lower() == 'scissor') and (player2['Choice'].lower() == 'paper'):
    print('Winner -',player1['Name'])
    elif (player2['Choice'].lower() == 'scissor') and (player1['Choice'].lower() == 'paper'):
    print('Winner -',player2['Name'])
    elif (player1['Choice'].lower() == 'paper') and (player2['Choice'].lower() == 'rock'):
    print('Winner -',player1['Name'])
    elif (player2['Choice'].lower() == 'paper') and (player1['Choice'].lower() == 'rock'):
    print('Winner -',player2['Name'])
    elif player1['Choice'] == player2['Choice']:
    print('Oh !! Its a Draw !')
    else:
    print('Sorry, Please give Proper Input')
     
    #4
    Sathish_65 and Alona Sorochynska like this.
  5. AnithaSanjeevan

    AnithaSanjeevan Customer
    Customer

    Joined:
    Jan 7, 2020
    Messages:
    3
    Likes Received:
    2
    Write a code to generate a dictionary that contains (i, i*i) such that i is an number between 1 and n (both included). and then the program should print the dictionary.

    number = int(input('Enter Number to generate dictionary of squares '))
    tempdict = {}
    for n in list(range(1,number+1)):
    tempdict.update({n:n*n})
    print('Output Dictionary :\n',tempdict)
     
    #5
  6. Allah Baksh

    Allah Baksh Member

    Joined:
    Jan 15, 2020
    Messages:
    2
    Likes Received:
    0
    Hi Nimisha,

    Done with the assignment.

    ### Ex. Write a code to create a list of prime numbers between 2000 and 3000
    prime_numbers = [i for i in range(2000,3000) if i%2 !=0]
    print(prime_numbers)

    # Ex. write a code to create a list of first 100 prime numbers
    prime_numbers = [i for i in range(0,100) if i%2 !=0]
    print(prime_numbers)

    #Ex. Write a code to generate a dictionary that contains (i, i*i) such that i is an number between 1 and n (both included).
    #and then the program should print the dictionary.

    n=7
    dic={}
    for i in range(1,n):
    dict={i:i*i}
    dic.update(dict)
    print(dic)
     
    #6
  7. V Abhilash Kumar

    V Abhilash Kumar New Member

    Joined:
    Oct 18, 2019
    Messages:
    1
    Likes Received:
    0
    Write code to generate a dictionary that contains (i, i*i) such that i is a number between 1 and n (both included). and then the program should print the dictionary.

    Sq=dict()
    n=int(input("Enter the range up to which squares you wish to know"))
    for i in range(1,n+1):
    Sq[ i ]=i*i
    print(Sq)
    ----------------------------------------------------------------------
    n=int(input("Enter the range"))
    sq={i:i*i for i in range(n+1)}
    print(sq)

    • first 100 prime numbers
    Prime =[ ]
    for n in range(1,550):
    for i in range (2,n):
    if n%i==0:
    break
    else:
    Prime.append(n)
    print(Prime[0:101])

    • prime b/w 2000 to 3000
    Prime_2k=[ ]
    for n in range(2000,3001):
    for i in range (2,n):
    if n%i==0:
    break
    else:
    Prime_2k.append(n)
    print(Prime_2k)
     
    #7
    Last edited: Jan 26, 2020
  8. Sangram (2946)

    Joined:
    Feb 25, 2014
    Messages:
    11
    Likes Received:
    1
    1. Rock Paper Scissor Game
    Player1 = input('Enter Name of Player 1:')
    Player1_Choice = input('Player 1 Choice:')
    Player2 = input('Enter Name of Player 2:')
    Player2_Choice = input('Player 2 Choice:')

    if Player1_Choice.capitalize() == 'Rock' and Player2_Choice.capitalize() == 'Rock':
    print("DRAW")
    elif Player1_Choice.capitalize() == 'Rock' and Player2_Choice.capitalize() == 'Scissor':
    print("Player ",Player1.capitalize(),": Wins")
    elif Player1_Choice.capitalize() == 'Rock' and Player2_Choice.capitalize() == 'Paper':
    print("Player ",Player2.capitalize(),": Wins")

    elif Player1_Choice.capitalize() == 'Paper' and Player2_Choice.capitalize() == 'Rock':
    print("Player ",Player1.capitalize(),": Wins")
    elif Player1_Choice.capitalize() == 'Paper' and Player2_Choice.capitalize() == 'Scissor':
    print("Player ",Player2.capitalize(),": Wins")
    elif Player1_Choice.capitalize() == 'Paper' and Player2_Choice.capitalize() == 'Paper':
    print("DRAW")

    elif Player1_Choice.capitalize() == 'Scissor' and Player2_Choice.capitalize() == 'Rock':
    print("Player ",Player2.capitalize(),": Wins")
    elif Player1_Choice.capitalize() == 'Scissor' and Player2_Choice.capitalize() == 'Scissor':
    print("DRAW")
    elif Player1_Choice.capitalize() == 'Scissor' and Player2_Choice.capitalize() == 'Paper':
    print("Player ",Player2.capitalize(),": Wins")
    else:
    print("Wrong Entry")

    2. Write a code to create a list of prime numbers between 2000 and 3000
    lst = []
    for i in range(2000,3000):
    for j in range(2,i):
    if i%j==0:
    break
    else:
    lst.append(i)
    print(lst)​

    3. write a code to create a list of first 100 prime numbers

    lst = []
    for i in range(0,1000):
    for j in range(2,i):
    if i%j==0:
    break
    else:
    lst.append(i)
    l = len(lst)
    if l == 100:
    break
    print(lst)
    4. Write a code to generate a dictionary that contains (i, i*i) such that i is an number between 1 and n (both included). and then the program should print the dictionary.

    n=25
    dictchk ={}
    for i in range(1,n+1):
    dictchk.update ({i:i*i})
    print(dictchk)
     
    #8
    Last edited: Jan 27, 2020
  9. AnithaSanjeevan

    AnithaSanjeevan Customer
    Customer

    Joined:
    Jan 7, 2020
    Messages:
    3
    Likes Received:
    2
    Write a code to create a list of prime numbers between 2000 and 3000

    for n in list(range(1000,2000+1)):
    for m in list(range(1,n+1)):
    if(m!=1 and m!=n):
    if(n%2==0):
    IsPrime=0
    break
    else:
    IsPrime=1
    if(IsPrime == 1):
    print(n)
     
    #9
  10. MJ Services

    MJ Services Active Member

    Joined:
    Nov 29, 2019
    Messages:
    15
    Likes Received:
    0
    write a code to ccreate a list of first 100 prime numbers
    #have tried this code but neither this is showing error nor its running. Whats the issue?

    lst=[]
    num = 1
    if num >=1:
    for i in range(2, num):
    if num % i != 0:
    lst=lst.append[num]
    print(lst)
    if len(lst) == 100:
    break
     
    #10
  11. MJ Services

    MJ Services Active Member

    Joined:
    Nov 29, 2019
    Messages:
    15
    Likes Received:
    0
    This code runs for odd numbers.
     
    #11
  12. MJ Services

    MJ Services Active Member

    Joined:
    Nov 29, 2019
    Messages:
    15
    Likes Received:
    0
    Can someone share paper scissor problem here?
     
    #12
  13. Kavitha_47

    Kavitha_47 Member

    Joined:
    Nov 9, 2019
    Messages:
    4
    Likes Received:
    0
    Hi Nimisha,
    please find the paper stone scissor game program

    # Stone- Paper-Scissor game
    while True:
    print("Welcome to STONE-PAPER-SCISSOR ")
    player1= input("Please enter player1's name:").lower()
    player2 = input("please enter player2's name:").lower()
    print("\nEnter your choices\nS ----- scissor\nT ----- stone\nP ----- paper")
    Flag1=0
    Flag2=0
    while True:
    choice1= input(f"Please enter {player1}'s choice: ").lower()
    choice2= input(f"Please enter {player2}'s choice: ").lower()
    string1=f"\n----{player1} is the winner!!----"
    string2=f"\n----{player2} is the winner!!----"
    if choice1==choice2:
    print("It's a Draw")
    elif choice1=="p"and choice2=="t":
    print(string1)
    Flag1=Flag1+1
    elif choice1=="p"and choice2=="s":
    print(string2)
    Flag2=Flag2+1
    elif choice1=="t"and choice2=="p":
    print(string2)
    Flag2=Flag2+1
    elif choice1=="t"and choice2=="s":
    print(string1)
    Flag1=Flag1+1
    elif choice1=="s"and choice2=="t":
    print(string2)
    Flag2=Flag2+1
    elif choice1=="s"and choice2=="p":
    print(string1)
    Flag1=Flag1+1
    else:
    print("\nMake a correct Entry")
    break
    check=input("Want to continue? ").lower()
    if check !="yes":
    print(f'''\n Total Points:
    {player1}-----{Flag1}
    {player2}-----{Flag2}\n\n
    ----------------------------------Game over------------------------------''' )
    break

    Thanks,
    Kavitha
     
    #13
  14. Kavitha_47

    Kavitha_47 Member

    Joined:
    Nov 9, 2019
    Messages:
    4
    Likes Received:
    0
    Hi Nimisha,
    Please check the below codes

    1.generation of First 100 prime numbers
    prime_numbers=[]
    count=0
    for i in range(1,300):
    if i % 2 == 0:
    prime_numbers.append(i)
    count+=1
    if count==100:
    break
    else:
    continue
    print(f"Prime numbers between first {count}\n {prime_numbers}")

    2. Generation of prime numbers between 2000 to 3000
    prime_numbers=[ ]
    for i in range(2000,3000):
    if i % 2 == 0:
    prime_numbers.append(i)
    else:
    continue
    print(f"Prime numbers between 2000 to 3000\n {prime_numbers}")
     
    #14
  15. Debi Prasad Rajguru

    Joined:
    Jul 22, 2019
    Messages:
    3
    Likes Received:
    0
    Class assignment codes
     

    Attached Files:

    #15
  16. _49336

    _49336 Member
    Alumni

    Joined:
    Nov 23, 2018
    Messages:
    8
    Likes Received:
    0
    prime_dist = {}
    prime_dist_is = False
    k = 0
    rnd = 0
    for i in range(1,100):
    if i < 6:
    rnd = i
    else:
    rnd = round(i/2)
    for j in range(2,rnd):
    if i%j == 0:
    print(i, " is not a prime number")
    prime_dist_is = False
    break
    else:
    prime_dist_is = True
    if prime_dist_is == True:
    prime_dist[k] = i
    k = k + 1
     
    #16
  17. _49336

    _49336 Member
    Alumni

    Joined:
    Nov 23, 2018
    Messages:
    8
    Likes Received:
    0
    Player1 = input('please enter your choise Rock/ Paper/ Scissor: ')
    Player2 = input('please enter your choise Rock/ Paper/ Scissor: ')
    Player1_choise = Player1.capitalize().lower()
    Player2_choise = Player2.capitalize().lower()
    Game_input = {'rock','paper','scissor'}
    if Player1_choise not in Game_input or Player2_choise not in Game_input:
    print('Only following values are allowed',Game_input, 'entered values Player1 = ',Player1,' ,Player2 = ',Player2)
    else:
    if Player1_choise == 'rock' and Player2_choise == 'scissor':
    print('Player 1 wins the game, player1 choise = ',Player1_choise,' Player2 choise = ',Player2_choise)
    elif Player1_choise == 'scissor' and Player2_choise == 'paper':
    print('Player 1 wins the game, player1 choise = ',Player1_choise,' Player2 choise = ',Player2_choise)
    elif Player1_choise == 'paper' and Player2_choise == 'rock':
    print('Player 1 wins the game, player1 choise = ',Player1_choise,' Player2 choise = ',Player2_choise)
    else:
    print('Player 2 wins the game, player1 choise = ',Player1_choise,' Player2 choise = ',Player2_choise)
     
    #17
  18. Aniket Srivastava_2

    Aniket Srivastava_2 New Member

    Joined:
    Dec 4, 2019
    Messages:
    1
    Likes Received:
    0
    Q.1 - To print dictionary contains value by i:i*i


    Dict={i:i*i for i in range(1,n+1)}

    Number=int(input("Enter your number to check --> "))

    print(Dict)



    Q.2- Print all prime number between 1 to 100


    lower = int(input("Enter Number :"))

    upper = int(input("Enter Number :"))


    print("Prime numbers between", lower, "and", upper, "are:")


    for num in range(lower, upper + 1):

    # all prime numbers are greater than 1

    if num > 1

    for i in range(2, num):

    if (num % i) == 0:

    break

    else:

    print(num)



    Q.3- Print prime number between 2000 to 3000

    lower = 2000

    upper = 3000


    print("Prime numbers between", lower, "and", upper, "are:")


    for num in range(lower, upper + 1):

    # all prime numbers are greater than 1

    if num > 1:

    for i in range(2, num):

    if (num % i) == 0:

    break

    else:

    print(num)

    Regards,
    Aniket Srivastava
     
    #18
  19. undefined undefined_127

    Joined:
    Sep 1, 2019
    Messages:
    1
    Likes Received:
    0
    1.Write a code to generate a dictionary that contains (i, i*i) such that i is an number between 1 and n (both included). and then the program should print the dictionary.

    dict={}
    n=int(input("Enter a number"))
    for i in range(1,n+1):
    dict.update({i:i*i})
    print(dict)


    2. write a code to create a list of first 100 prime numbers

    lst=[]
    for i in range(1,101):
    count=0
    for j in range(1,i+1):
    if(i%j==0):
    count=count+1
    if count>2:
    break
    if(count==2):
    lst.append(i)
    print(lst)

    3. Write a code to create a list of prime numbers between 2000 and 3000

    lst=[]
    for i in range(2000,3000):
    count=0
    for j in range(1,i+1):
    if(i%j==0):
    count=count+1
    if count>2:
    break
    if(count==2):
    lst.append(i)
    print(lst)
    print("Number of prime numbers in the range 2000 to 3000 are: ",len(lst))
     
    #19
  20. Allah Baksh

    Allah Baksh Member

    Joined:
    Jan 15, 2020
    Messages:
    2
    Likes Received:
    0
    oops! let me change the condition
     
    #20
  21. MJ Services

    MJ Services Active Member

    Joined:
    Nov 29, 2019
    Messages:
    15
    Likes Received:
    0
    HI,
    Is class for 29th Jan ON? I could not login it.
     
    #21
  22. Abdul Rashid

    Abdul Rashid Member

    Joined:
    Dec 28, 2019
    Messages:
    4
    Likes Received:
    0
    Can u please check my notebook for project i have solved some questions
     

    Attached Files:

    #22
  23. Anjali Batra_1

    Joined:
    Sep 28, 2019
    Messages:
    2
    Likes Received:
    0
    Nimisha , can you please check if I have solved this question correctly.

    #Normal distribution.docx - 2 problem
    #emergency room has a mean cost of $328
    #standard deviation of $92
    a. probablity that the cost of room will be more than $200 i.e from 200 to + infinity
    mu = 328
    sigma = 92
    1 - stats.norm.cdf(x = 200, loc = mu, scale = sigma)
    Ans:
    .917933422 is the probability of more than $200

    #b. what is the probablity that the value would be less than 250 i.e from -infinty to 250
    stats.norm.cdf(x = 250, loc = mu, scale = sigma)
    Ans:
    0.19826741629443773 for less than 250

    #c.What is the probability that the cost will be between $300 and $400?
    #i.e. find area from - infinty to 300 and -infinty to 400 and subtract to find the probablity
    stats.norm.cdf(x = 400, loc = mu, scale = sigma) - stats.norm.cdf(x = 300, loc = mu, scale = sigma)
    Ans : 0.40264

    d.if the cost is below 8% i.e from -infinty to 8 find cost of the room
    stats.norm.ppf(q = 0.08, loc = mu, scale = sigma)
    Ans: 198
     
    #23
  24. _49336

    _49336 Member
    Alumni

    Joined:
    Nov 23, 2018
    Messages:
    8
    Likes Received:
    0
    Please find solved assignments for Normal Distribution.
     

    Attached Files:

    #24
  25. MJ Services

    MJ Services Active Member

    Joined:
    Nov 29, 2019
    Messages:
    15
    Likes Received:
    0
    Dear Nimisha,

    How do we check usability of all these functions found in dir or where can we check how to use them???

    'all', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'display', 'divmod', 'enumerate', 'eval', 'exec', 'filter', 'float', 'format', 'frozenset', 'get_ipython', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']
     
    #25
  26. MJ Services

    MJ Services Active Member

    Joined:
    Nov 29, 2019
    Messages:
    15
    Likes Received:
    0
    Hi Nimisha,
    Is it necessary that for calculation or any kind of data analysis the column header in the dataframe should be a single word. What if it is made up of two or three words separate by space?
    While executive a project i have got a message that Count take one word and not two. Please clarify.
     
    #26
  27. MJ Services

    MJ Services Active Member

    Joined:
    Nov 29, 2019
    Messages:
    15
    Likes Received:
    0
    Did anyone get the syntax for calculating different in date timestamp for project 1 of customer service analysis.
     
    #27
  28. Nimisha Pandey

    Nimisha Pandey Well-Known Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    65
    Likes Received:
    69
    Any variable needs to follow the rule for identifier making .. discussed in the first day notebook.
    if it does not in that case for data frame you can use them as data frame['var name']Any variable needs to follow the rule for identifier making .. discussed in the first day notebook.
    if it does not in that case for data frame you can use them as data frame['var name']
     
    #28
  29. Nimisha Pandey

    Nimisha Pandey Well-Known Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    65
    Likes Received:
    69
    explore 'relativvedelta.relativedelta' in package dateutils
     
    #29
  30. Nimisha Pandey

    Nimisha Pandey Well-Known Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    65
    Likes Received:
    69
    by calling help on them using help(object name.function)
     
    #30
  31. Debi Prasad Rajguru

    Joined:
    Jul 22, 2019
    Messages:
    3
    Likes Received:
    0
    Did anyone has tried for the below two project questions
    For the below statements you need to state the Null and Alternate and then provide a statistical test to accept or reject the Null Hypothesis along with the corresponding ‘p-value’.
    • Whether the average response time across complaint types is similar or not (overall). Is the question here that avg response time by complaint type is same or different. I am not clear what is (overall means). H0 = Avg response time is same, Ha = Not same???

    • Are the type of complaint or service requested and location related? Here, i am trying do a chi-square test but when i use the below syntax it says invalid: ob_freq = pd.crosstab(nyc311.Complaint Type, nyc311.Location Type)
    upload_2020-2-12_12-31-39.png

    Any clue or guidance....
     
    #31
  32. Vengatesh Nathan

    Vengatesh Nathan New Member

    Joined:
    Aug 14, 2019
    Messages:
    1
    Likes Received:
    0
    Can someone share Nielsen Csv with me.I am not able to find it in the drive.I missed the T test class.Need to go through the recordings.Can someone please help me with the file.
     
    #32
  33. Debi Prasad Rajguru

    Joined:
    Jul 22, 2019
    Messages:
    3
    Likes Received:
    0
    Here you go...
     

    Attached Files:

    #33
  34. Menga Vineeth Sai Raj

    Joined:
    Dec 24, 2019
    Messages:
    1
    Likes Received:
    0
    Hi Nimisha,
    can you help me out on datetime conversion for Project1 ?
    i tried in the below code.But it threw me the error : "
    TypeError: cannot convert the series to <class 'int'>"

    import pandas as pd
    import datetime as dt
    sr=pd.read_csv('/home/ubuntu/work/Jan 20/311sr.csv')
    d1=sr['Created Date']
    d2=sr['Closed Date']
    x = dt.datetime(d2)-dt.datetime(d1)
    x
     
    #34
    Last edited: Feb 14, 2020
  35. Nimisha Pandey

    Nimisha Pandey Well-Known Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    65
    Likes Received:
    69
    Hi Debi,
    variable or column names also need to follow the identifier rules as discussed in 1st / 2nd class. here the variable name has a space... so is not valid.
    for variable//column names which are invalid you will have to use them as nyc311['Complain Type'] i.e. within square brackets as strings
     
    #35
  36. MJ Services

    MJ Services Active Member

    Joined:
    Nov 29, 2019
    Messages:
    15
    Likes Received:
    0
    Hi Nimisha,

    Every project has time component, i request you to take up one example based on time and explain the use of time package. My all projects are stuck because of that. Have started with Project 1 & project 4.
     
    #36
  37. Sangram (2946)

    Joined:
    Feb 25, 2014
    Messages:
    11
    Likes Received:
    1
    Yes , first you convert 'Created Date' & ' Closed Date' columns datatype from object to datetime ,using 'to_datetime' from datetime module
    then Subtract Open Date from Closed date
     
    #37
  38. MJ Services

    MJ Services Active Member

    Joined:
    Nov 29, 2019
    Messages:
    15
    Likes Received:
    0
    Can someone help to get the desired result. Error shows that it cannot display int.

    import datetime as dt
    difference = dt.datetime(project1.closed_date, project1.created_date)
    ---------------------------------------------------------------------------
    TypeError Traceback (most recent call last)
    <ipython-input-14-2542f0461481> in <module>
    ----> 1difference = dt.datetime(project1.closed_date, project1.created_date)

    /opt/anaconda3/lib/python3.7/site-packages/pandas/core/series.py in wrapper(self)
    91 return converter(self.iloc[0])
    92 raise TypeError("cannot convert the series to "
    ---> 93 "{0}".format(str(converter)))
    94
    95 wrapper.__name__ = "__{name}__".format(name=converter.__name__)

    TypeError: cannot convert the series to <class 'int'>
     
    #38
  39. Nimisha Pandey

    Nimisha Pandey Well-Known Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    65
    Likes Received:
    69
    hey
    dt.datetime() --this creates a datetime object
    to find difference u need date1 - date2
     
    #39
  40. Sangram (2946)

    Joined:
    Feb 25, 2014
    Messages:
    11
    Likes Received:
    1

    You can also use to_datetime from pandas and subtract dates.

    df1['Created Date'] = pd.to_datetime(df1['Created Date'])
    df1['Closed Date'] = pd.to_datetime(df1['Closed Date'])
    df1['Request_Closing_Time'] = df1['Closed Date'] - df1['Created Date']
     
    #40
  41. Alona Sorochynska

    Joined:
    Dec 13, 2019
    Messages:
    2
    Likes Received:
    0
    Hello! I don't really understand the task: Order the complaint types based on the average ‘Request_Closing_Time’ ('Days' in my data), grouping them for different locations.
    Is it something like this?
    data[['City','Complaint Type','Days']].groupby(['City','Complaint Type']).mean()
    Do I have to plot it or I understand the task in the wrong way?
     
    #41
  42. Anjali Batra_1

    Joined:
    Sep 28, 2019
    Messages:
    2
    Likes Received:
    0
    This is regarding project 1 Customer Analysis
    Please note: For the below statements you need to state the Null and Alternate and then provide a statistical test to accept or reject the Null Hypothesis along with the corresponding ‘p-value’.

    Whether the average response time across complaint types is similar or not
    Should we be doing Anova analysis over here as we are comparing means of various groups

    Are the type of complaint or service requested and location related
    Should we be performing chisquare test over here
     
    #42
  43. Nimisha Pandey

    Nimisha Pandey Well-Known Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    65
    Likes Received:
    69
    Hi,
    you need to get average Request closing time for each city. and then order that data by that average
     
    #43
  44. Sangram (2946)

    Joined:
    Feb 25, 2014
    Messages:
    11
    Likes Received:
    1
    As Nimisha mentioned , you need to get average of request Closing Time, before that you may need to convert datatype of request closing time to float (convert time into seconds/hours) as it may throw error while calculating mean.
     
    #44
    Last edited: Feb 19, 2020
    Alona Sorochynska likes this.
  45. Alona Sorochynska

    Joined:
    Dec 13, 2019
    Messages:
    2
    Likes Received:
    0
    Hello. HELP!
    My test is giving me NaNs: F_onewayResult(statistic=nan, pvalue=nan)
    I have a data smth like this:

    ___Complaint_______Seconds
    0
    __Agency Issues___18937.166667
    1
    __Animal Abuse____16654.392508
    ...

    My first step is:
    s1 = data.loc[data.Complaint == 'Agency Issues','Seconds']
    s2 = data.loc[data.Complaint == 'Animal Abuse','Seconds']
    ...

    My next step is:
    stats.f_oneway(s1,s2, ...)
    And the answer is:
    F_onewayResult(statistic=nan, pvalue=nan)
    There is no NaNs in my data and I was trying to transform Seconds to arrays and the answer is always the same... NAN :(
     
    #45
  46. _49336

    _49336 Member
    Alumni

    Joined:
    Nov 23, 2018
    Messages:
    8
    Likes Received:
    0
    Hello Need help ---
    I'm plotting a graph with all complaints closed after the due date by city. It is giving me following error

    TypeError: only size-1 arrays can be converted to Python scalars.

    I'm passing the index and it is array of cities. The data i'm working on is from Customer Service Requests Analysis

    ccadt = nyc_311.groupby(nyc_311.City[(nyc_311.Closed_Date > nyc_311.Due_Date)]).agg({'Closed_Date': 'count'})
    plt.figure(figsize = (10,5))
    plt.bar(x = ccadt.index, height = ccadt.values, color = 'green')
    plt.show()
     
    #46
  47. Sangram (2946)

    Joined:
    Feb 25, 2014
    Messages:
    11
    Likes Received:
    1
    I did it other way i.e preprocessing data and then plot chart
     
    #47
  48. Nimisha Pandey

    Nimisha Pandey Well-Known Member
    Trainer

    Joined:
    Aug 4, 2017
    Messages:
    65
    Likes Received:
    69
    data.Complaint.value_counts() ... use the top 5 complaint
    s1, s2,s3,s4,s5
     
    #48
  49. Devika Dixit

    Devika Dixit New Member

    Joined:
    Jan 25, 2020
    Messages:
    1
    Likes Received:
    0
    hey guys I have on question plz answer
    cars=["audi","ferrari","volvo","sedan","wolzvehan"]
    I want to print next value of input by user as in if user enter "volvo" then print value should be "sedan".
    My end of code:
    cars=["audi","ferrari","volvo","sedan","wolzvehan"]
    input("Enter the car name")
    for i ,nexti in zip(cars,cars[1::]) :
    print("i",i)
    print("nexti",nexti)

    http://localhost:8888/notebooks/Untitled4.ipynb


    and unable to upload file also getting error of the uploaded file does not have an allowed extension …..and have already given file.ipynb extension
     
    #49
  50. Niyas Manzoor

    Niyas Manzoor Member

    Joined:
    Oct 15, 2019
    Messages:
    4
    Likes Received:
    0

    Hi Nimisha Maam,

    Hi,

    I am trying to do Q4 in proj 1

    data_df.groupby('Complaint Type')['Mean Response Time'].mean()[['Mean Response Time']].sort_values('Complaint Type')

    The below error comes

    -----------------------------------------------------------------

    KeyError Traceback (most recent call last)
    <ipython-input-80-e8373d80183c> in <module>
    1 #Q4 :
    2
    ----> 3data_df.groupby('Complaint Type')['Mean Response Time'].mean()[['Mean Response Time']].sort_values('Complaint Type')

    ~\Anaconda3\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
    1108 key = check_bool_indexer(self.index, key)
    1109
    -> 1110return self._get_with(key)
    1111
    1112 def _get_with(self, key):

    ~\Anaconda3\lib\site-packages\pandas\core\series.py in _get_with(self, key)
    1150 # handle the dup indexing case (GH 4246)
    1151 if isinstance(key, (list, tuple)):
    -> 1152return self.loc[key]
    1153
    1154 return self.reindex(key)

    ~\Anaconda3\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
    1422
    1423 maybe_callable = com.apply_if_callable(key, self.obj)
    -> 1424return self._getitem_axis(maybe_callable, axis=axis)
    1425
    1426 def _is_scalar_access(self, key: Tuple):

    ~\Anaconda3\lib\site-packages\pandas\core\indexing.py in _getitem_axis(self, key, axis)
    1837 raise ValueError("Cannot index with multidimensional key")
    1838
    -> 1839return self._getitem_iterable(key, axis=axis)
    1840
    1841 # nested tuple slicing

    ~\Anaconda3\lib\site-packages\pandas\core\indexing.py in _getitem_iterable(self, key, axis)
    1131 else:
    1132 # A collection of keys
    -> 1133keyarr, indexer = self._get_listlike_indexer(key, axis, raise_missing=False)
    1134 return self.obj._reindex_with_indexers(
    1135 {axis: [keyarr, indexer]}, copy=True, allow_dups=True

    ~\Anaconda3\lib\site-packages\pandas\core\indexing.py in _get_listlike_indexer(self, key, axis, raise_missing)
    1090
    1091 self._validate_read_indexer(
    -> 1092keyarr, indexer, o._get_axis_number(axis), raise_missing=raise_missing
    1093 )
    1094 return keyarr, indexer

    ~\Anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_read_indexer(self, key, indexer, axis, raise_missing)
    1175 raise KeyError(
    1176 "None of [{key}] are in the [{axis}]".format(
    -> 1177key=key, axis=self.obj._get_axis_name(axis)
    1178 )
    1179 )

    KeyError: "None of [Index(['Mean Response Time'], dtype='object', name='Complaint Type')] are in the [index]"

    PLS HELP !!!

    Thanks
    Niyas
     
    #50

Share This Page