back soft

مطالب مرتبط با «python list of objects» در back soft | نویسنده: استخدام کار

How to constuct a column of data frame recursively with pandas-python?

Vote count: 0 Give such a data frame df: id_ val 11111 12 12003 22 88763 19 43721 77 ... I wish to add a column diff to df, and each row of it equals to, let's say, the val in that row minus the diff in the previous row and multiply 0.4 and then add diff in the previous day: diff = (val - diff_previousDay) * 0.4 + diff_previousDay And the diff in the first row equals to val * 4 in that row. That is, the expected df should be: id_ val diff 11111 12 4.8 12003 22 11.68 88763 19 14.608 43721 77 ... ...

ادامه مطلب

How can I concatenate a big list of unique words once?

Vote count: 0 It is hard to explain what I am trying to say so I am best off giving an example. Lets say I had the following data - word1, word2word3, word4 What I would need is an output is the following - word1 word2word1 word3word1 word4word2 word1word2 word3word2 word4word3 word1word3 word2word3 word4word4 word1word4 word2word4 word3 So a complete mix of all the combinations of words. In total I have 300x300 rows and columns so I know it will be a big result but do not know the best way to g...

ادامه مطلب

Python exception "can't multiply sequence by non-int of type 'float'

Vote count: 0 My 12 year old is leaing python scripting. He is writing a very simple code to calculate the discount on a article. Following is the code and it throws the exception on the 3rd line in the code. The exception is: Traceback (most recent call last): File "C:/Users/basam/AppData/Local/Programs/Python/Python35/discounts.py", line 3, in discount=0.1*price TypeError: can't multiply sequence by non-int of type 'float' price=input('how much is your item?') if int(price)...

ادامه مطلب

How to know if a variable is in an attribute of an object in a list?

Vote count: 0 To check if a variable is in a list, I know that one can use if variable in list. In my instance, I have a list of objects, all of which have the attribute "id", I want to check if an object in a list has a specific ID, but I'm not sure how I would go about doing that. I already tried looking this up on google as well as here but I couldn't find any relevant results. That might be because I don't really know how to phrase my question correctly, so if my question doesn't make sense ...

ادامه مطلب

Python n elements from list by index

Vote count: 0 Question: I have a list of arrays such as: a = [array([0, 4]), array([1, 3, 2])] From another variable X, I want to take two subsets which are chosen by the index in each array in a. X = [0.1, 0.7, 0.9, 0.2, 0.3] What I want to have is now: result_1 = [0.1, 0.3] result_2 = [0.7, 0.2, 0.9] My solution would be to use a for loop such as: def getresult(X, indices): result = [] for i in indices: result.append(X[i]) retu result This works fine: getresult(X, a[0]) [0.1, 0.3] My previous ...

ادامه مطلب

How to find the index number of list that in dictionary?

Vote count: 0 The example list { 'date': array(['06/08/2016', '06/09/2016', '06/10/2016']), 'close': array([ 923.13, 914.25, 909.42]) } I try to get the Date of close is 914.25 that is list['date'][2] but i don't know how to get index 2 for close. Thank you. asked 3 mins agoBarbiyong 1 Answer Vote count: 0 You can solve it with zip() and next(): >>> d = { ... 'date': ['06/08/2016', '06/09/2016', '06/10/2016'], ... 'close': [ 923.13, 914.25, 909.42] ... } >>> a = 914.25 >>> next(date for date, am...

ادامه مطلب

Inserting a list of financial data into MySQL via Python

Vote count: 0 Using Python and ystockquote - I import a dictionary of around 80+ values of financial data. I've setup a MySQL table with receiving columns with values like - previous_close, shares_owned, change_from_52_week_low. I'm getting stuck on sending the data from Python as a list to MySQL. I have broken the dictionary into just the values - so that the Python list would be all that is imported into the SQL table. What do I need to get the list of Python retus into the respective MySQL co...

ادامه مطلب

Rapid compression of multiple lists with value addition

Vote count: 0 I am looking for a pythonic way to iterate through a large number of lists and use the index of repeated values from one list to calculate a total value from the values with the same index in another list. For example, say I have two lists a = [ 1, 2, 3, 1, 2, 3, 1, 2, 3] b = [ 1, 2, 3, 4, 5, 6, 7, 8, 9] What I want to do is find the unique values in a, and then add together the corresponding values from b with the same index. My attempt, which is quite slow, is as follows: a1=list...

ادامه مطلب

Is Thread.sleep() waste of time for listening in Java?

Vote count: 0 Suppose I have a nametag, which is UI component in GUI program. The nametag will constantly change its text based on the data. If the user change his/her name data, then he/she will see the change in nametag. For this task, my code looks like this: Thread thread = new Thread(new Ruable(){ @Override public void run() { while (true){ String name = data.getName(); nametag.setText(name); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } }); Since th...

ادامه مطلب

Center Pop Up Menu in clicked row of list

Vote count: 0 I want that my pop up menu appear next to the clicked row. Look at the picture after I click the "..." button: http://postimg.org/image/s35znsaq3/ This is my code for the Pop Up Menu: private void showPopUpMenu(final User user) { View menuItemView = findViewById(R.id.moreActions); PopupMenu popUpMenu = new PopupMenu(ContactsListActivity.this, menuItemView); popUpMenu.getMenuInflater().inflate(R.menu.pop_up_menu, popUpMenu.getMenu()); // Hide buttons for missing user's information M...

ادامه مطلب

List of tuple to string in Python

Vote count: 0 I have a list like this: l = ['b', '7', 'a', 'e', 'a', '6', 'a', '7', '9', 'c', '7', 'b', '6', '9', '9', 'd', '7', '5', '2', '4', 'c', '7', '8', 'b', '3', 'f', 'f', '7', 'b', '9', '4', '4'] and I want to make a string from it like this: 7bea6a7ac9b796d957427cb8f37f9b44 I did: l = (zip(l[1:], l)[::2]) s = [] for ll in l: s += ll print ''.join(s) But is there any simpler way? May be, in one line? asked 1 min agopushpen.paul Let's block ads!...

ادامه مطلب

IndexError: list index out of range. Why do I get this error in the second function but not the first function?

Vote count: 0 The function derivative computes the derivative of a polynomial; the degree of each entry needs to be reduced by one, each entry must be multiplied by the previous degree, and the term at degree[0] needs to be removed. This code lst = [1,2,3] """This list represents the polynomial 3x^2+2x+1""" """This function moves each entry one index down and removes the last entry""" def move(lst): copy = list(lst) for i in range(len(lst)): lst[i-1] = copy[i] del lst[-1] print lst move(lst) pro...

ادامه مطلب

Python C Extension - Memory Leak despite Refcount = 1 on returned PyObjects

Vote count: 0 I'm repeatedly calling a python module I wrote in C++ using the Python C API. My python program repeatedly calls my module's pyParse function, which does a bunch of stuff and retus a PyTuple that contains more PyTuple objects as elements. Every retued object ends up with a PyObject->refcnt of 1, so you know the object should be deleted when it goes out of scope in python. I repeatedly call this module with something like the following python code: import my_module #this is my c++ m...

ادامه مطلب

Jquery or PHP group array of objects by date field

Vote count: 0 So I have json response containing data formatted for creating a chart (using Canvas.js), it's an array of objects, each of which contains y value (which is int) and label (which is SQL date, like 2016-02-06). What I need is to group these values by dates and get average from them. Data are sorted by date. The problem is, there can be random number of points for one day, and the other day may not have any points at all. So, I need kind of week index (calculating the week of the yea...

ادامه مطلب

How do I deserialize this XML back into an array of Point objects

Vote count: 0 The XML file is as follows I want to deserialize this XML back into Polygon objects. My Polygon class is as follows [XmlType("Polygon")] public class Polygon { [XmlElement("Points")] public Point[] points { get; set; } } My deserialization code is XmlSerializer serializer = new XmlSerializer(typeof(Polygon[]),new XmlRootAttribute("Polygons")); FileStream fs = new FileStream(filename, FileMode.Open); XmlReader reader = XmlReader.Create(fs); Polygon[] p; p = (Polygon[])serializer.Des...

ادامه مطلب

how to copy contents of a LISTVIEW to a text file?

Vote count: -2 enter image description here how can I solve this problem? asked 4 mins agoDaulet Ilakhunov Let's block ads!...

ادامه مطلب

How can I make Python 3's Print fit the size of the command prompt?

Vote count: 1 Python 3 can easily handle printing a lot of text: text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent vitae odio quis felis consectetur blandit. Etiam mattis vehicula ex id sodales. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris fermentum semper nisi vel aliquam. Ut nec facilisis lectus. Maecenas auctor blandit condimentum. Donec finibus orci ac imperdiet congue. Pellentesque sem leo, commodo non metus ac, posuere maximus lorem. Class aptent ...

ادامه مطلب

python: filter a nested list of strings with list comprehension

Vote count: 0 I am trying to use list comprehension to filter this list: inp = [['Fire 46.0.1', 'vlc 2.2.3','opt 0.9.9.10'], ['opt 0.9.9.11', 'notepad 6.9', 'adobe. 6.9', 'vlc 2.3.3']] into: out = [['Fire 46.0.1', 'vlc 2.2.3',], ['notepad 6.9', 'adobe. 6.9', 'vlc 2.3.3']] i.e. removing all the strings that start with opt. I am trying something like that: [soft for ls in inp if soft not soft.startswith('opt')] but something is wrong with the sintax.Any help? asked 2 mins agodiegus Let's block ads...

ادامه مطلب

Python property on a list

Vote count: 0 I am new to Python and I just discovered the properties. It works just fine when I try it on a simple variable but I caot make it work on a list. When executing the code below it will call two times the getter and not the setter. I know that in my example the property has no added value but it is to simplify. class C: def __init__(self): self._x=[1,2,3] @property def x(self): print("getter") retu self._x @x.setter def x(self,value): print("setter") self._x=value c = C() c.x[1]=4 pr...

ادامه مطلب

Listing all the variables in a Python class

Vote count: 0 I've made a class, and after the program has finished ruing, I want to list all the variables I have kinda like so var1: val var2: val etc my class looks like this class character: name = 'Player1' level = 1 str = 100 con = 80 sta = 150 critchance = 0.1 critdmg = 0.5 # for battle hp = con * con thoughness = math.sqrt(sta) asked 2 mins agoPetter Petter Let's block ads!...

ادامه مطلب