object

Python object. How to pass a value to one specific method

Python object. How to pass a value to one specific method Question: I have a Python object that represents a camera dolly that moves along a track. The class can store and report its position along the track. I have three methods: MoveBy – which gets the distance from another object (Movie.yIncrement) MoveTo – which …

Total answers: 1

How can I convert an object dtype to integer by removing letter characters?

How can I convert an object dtype to integer by removing letter characters? Question: My question is related to a conversion of a dtype object to integer. Specifically, I want to remove the characters of the dtype and convert it to integer so I can handle it as an integer. I have the following dataframe: …

Total answers: 2

Python lambda groupby with aggagration result in syntax error

Python lambda groupby with aggagration result in syntax error Question: Hello i am struggling with the lambda groupby function in combination with a nested structure to get the result in the structure as shown in the example below: Target structure # This already works! ######################################################## # GM0014": { # "i1401": { # "score": 1.178, # …

Total answers: 1

How to avoid "pointing to same object" while creating nested dictionary using zip and map?

How to avoid "pointing to same object" while creating nested dictionary using zip and map? Question: I would like to avoid pointing to the same object in the below code. Please look at output and desired output stated below. Code: import random prototype = [{‘uniqueDict’: list()}] def mapme(somekey): global aa aa = [random.randint(0, 5), random.randint(6, …

Total answers: 1

Create List of Object 's for object parameter

Create List of Object 's for object parameter Question: im trying to create an Object name "TestA", TestA will has list of TestB object. When i create two object TestA and push deiffrent TestB’ to their list they has same value class testA: testBlist = [] def __init__(self, n) -> None: self.name = n pass …

Total answers: 2

Here is the problem discription: print(snake_array[0].x) AttributeError: 'list' object has no attribute 'x' . I cannot find the mistake

Here is the problem discription: print(snake_array[0].x) AttributeError: 'list' object has no attribute 'x' . I cannot find the mistake Question: class Test: def __init__(self, x, y, dir): self.x = x self.y = y self.dir = dir def snake_init(snake_array): snake_array.append([Test(300, 300, "RIGHT")]) snake_array.append([Test(301, 300, "RIGHT")]) snake_array.append([Test(302, 300, "RIGHT")]) print(snake_array[0].x) snake_array = [] snake_init(snake_array) Asked By: Hubert …

Total answers: 1

Can't get function within object to display value

Can't get function within object to display value Question: hey guys I’m currently learning oop but I’m having a bit of trouble with accessing values which I create or add to a object, currently I can’t work out how to get the value stored within getAge from datetime import date class Person: def __init__(self, name, …

Total answers: 2

Convert string to class object and add custom function to it in Python

Convert string to class object and add custom function to it in Python Question: I have a string path "path=D:/projects/file.ext". Is there a way to convert this string to class and add to it a method which will do something with file.ext? The file could be any type Does not matter. For example: my_file="D:/projects/file.ext" obj …

Total answers: 2

Add variable value for a specific variable but in another class

Add variable value for a specific variable but in another class Question: I have two classes, ClassA and ClassB, that both have variables var1 and var2. In ClassA, var1 is initialized to 1 and var2 is initialized to 2. ClassB inherits from ClassA. I want to be able to define/set the value of var1 in …

Total answers: 1

Python: convert str object to dataframe

Python: convert str object to dataframe Question: I have a string object as follows: time,exchange,fsym,tsym,close,high,low,open,volumefrom,volumeto 1660003200,NYSE,BTC,USD,100.1,103,99.1,100,30,10000 1660003260,NYSE,BTC,USD,101.3,104,100.1,102,39,12000 1660003320,NYSE,BTC,USD,100.9,103.2,98,100,32,100230 I am trying to convert this string object to a DataFrame. I have tried adding brackets "[]" around the data but that still didn’t work. Any suggestions would be greatly appreciated. Asked By: MathMan 99 || Source …

Total answers: 2