EDIT I found a quite nice solution and posted it below as an answer. The result will look like this: Some example data you can generate for this problem: resulting in: I’d like to group by calendar-week and by value of col1. Like this: resulting in: Then I want a plot to be generated like this: That mea…
Tag: python
How to modify Levenshtein algorithm, to know if it inserted, deleted, or substituted a character?
So I am trying to devise a spin off of the Levenshtein algorithm, where I keep track of what transformations I did in the string(inserted a, or substitute a for b). Example: Basically, say I am computing the edit distance of “bbd” and “bcd” The edit distance will be 1 and the transform…
How can I add a parameter request list in DHCP header with Scapy?
I try to make a DHCP pachet with parameter request list option and to add three parameters in that request. This is what i done but the pachet I see on Wireshark look`s to be malformed: I also try to pass the parametes as a list of codes of the parameters i want to be included in the request list,
How to get output of pandas .plot(kind=’kde’)?
When I plot density distribution of my pandas Series I use Is it possible to get output values of this plot? If yes how to do this? I need the plotted values. Answer There are no output value from .plot(kind=’kde’), it returns a axes object. The raw values can be accessed by _x and _y method of th…
How do I create test and train samples from one dataframe with pandas?
I have a fairly large dataset in the form of a dataframe and I was wondering how I would be able to split the dataframe into two random samples (80% and 20%) for training and testing. Thanks! Answer I would just use numpy’s randn: And just to see this has worked:
How do you declare a global constant in Python?
I have some heavy calculations that I want to do when my program starts, and then I want to save the result (a big bumpy matrix) in memory so that I can use it again and again. My program contains multiple files and classes, and I would like to be able to access this variable from anywhere, and if possible
Finding k closest numbers to a given number
Say I have a list [1,2,3,4,5,6,7]. I want to find the 3 closest numbers to, say, 6.5. Then the returned value would be [5,6,7]. Finding one closest number is not that tricky in python, which can be done using But I am trying not to put a loop around this to find k closest numbers. Is there a pythonic way
How do I connect to SQL Server via sqlalchemy using Windows Authentication?
sqlalchemy, a db connection module for Python, uses SQL Authentication (database-defined user accounts) by default. If you want to use your Windows (domain or local) credentials to authenticate to the SQL Server, the connection string must be changed. By default, as defined by sqlalchemy, the connection strin…
How to get sorted list inside a dictionary with json.dumps()
I have the following problem: having a python dictionary like the following: I would like to obtain an ordered json object such as: At the moment I use the following: But the two list inside my object are not sorted, and I get: probably because the custom JSONEncoder skips a type that already knows how to man…
How can I create a form from a list of models using WTForms?
I have a list of Prediction models. I want to bind them to a form and allow the use to post back. How can I structure my form so the post associates a Home/Away score with a Prediction model’s id field for each item I bind to the form? view form template I am unable to get my data to