ValueError: Must produce aggregated value in pandas

I’m getting a ValueError when applying np.sum that I need to product aggregated value. Any word of advise to fix this issue? Btw – This logic used to run for me before. df1 = self_id | id | rating | comment | 1 820 (blank) (blank) 2 823 strong good performance 3 826 weak (blank)… Read More ValueError: Must produce aggregated value in pandas

Why is my code giving a value error that the list index is out of range?

inp_list=[10,1,11,1,29,876,768,10,11,1,92,29,876] for i in range(len(inp_list)): for j in range(i+1, len(inp_list)): if (inp_list[i]==inp_list[j]): inp_list.remove(inp_list[i]) print(inp_list) In the code, I was trying to remove the duplicate elements in the list. It is giving me a ValueError for line if (inp_list[i]==inp_list[j):, I am not able to understand why is it showing me an error. I tried looping through… Read More Why is my code giving a value error that the list index is out of range?

Limiting user input to number of variables when using split() to prevent 'ValueError: too many values to unpack'?

a,b = map(int, input().split()) In the above code or anything similar, we use split to separate multiple inputs on a single line, typically separated with a space, and assign the results to the variables. This is very convenient feature, however I am facing a problem: Say I want to populate a list A with n… Read More Limiting user input to number of variables when using split() to prevent 'ValueError: too many values to unpack'?

value error(line 7 for name, home) when using csv library in python CS50P file i/o

import csv students = [] with open("stu1.csv") as file: reader = csv.reader(file) for name, home in reader: students.append({"name": name}, {"home": home}) for student in sorted(students, key =lambda student:student["name"]): print(f"{student[‘name’]} is from {student[‘home’]}") stu1.csv contains below data Harry, Number, Pivet Drive Ron, The burrow Draco, Malfoy manor >Solution : You were very close. There were actually… Read More value error(line 7 for name, home) when using csv library in python CS50P file i/o

open method in python not let me convert string to int

weird thing happens when I try to run this line of code: with open("snake score.txt", mode="r") as f: self.high_score = int(f.read()) it gives me: File "C:\Users\Lidor\PycharmProjects\100DaysOfCode\snake.py", line 77, in __init__ self.high_score = int(f.read()) ValueError: invalid literal for int() with base 10: ” the text inside the text is the number 0. Can someone tell me… Read More open method in python not let me convert string to int

Python Optimize multiple if-else based on truthy value

I have following code in Python where based on a boolean flag I need to check a list count, wondering if there is a better way to code this in Python? If var_true: if len(something) > 0: logger.console (“Something found”) else: raise AssertionError(“something was not found”) If not var_true: if len(something) == 0: logger.console (“Something… Read More Python Optimize multiple if-else based on truthy value

I would like to make my program display the order total/invoice

Here is what ive done: food =["cheeseburger", "smallchips", "drink"] prices =[2.50, 1.50, 1] x=0 myorderfood=[] myordercost=[] print("Burgers\n") print("Menu:") print("Cheeseburger. Cost – $2.50 each") print("Small chips. Cost – $1.50 each") print("Drink – Cola only. Cost – $1.00 each\n") I want to display an invoice at the end once the user has completed there order showing there… Read More I would like to make my program display the order total/invoice

Split pandas dataframe column based on the pipeline symbol

I have a pandas data frame which has a single column named Category. I want to split this Category column into 4 separate columns named A, B, C, D based on the pipeline symbol "||" Sample input: df[‘Category’] = Operations||Modification||Bank||Bank Process Sample output: df[‘A’] = Operations df[‘B’] = Modification df[‘C’] = Bank df[‘D’] = Bank… Read More Split pandas dataframe column based on the pipeline symbol