I have a list of paths taken from networkX by nx.shortest_simple_paths(g,s,d) and the paths are: What I am trying to do is to find two paths which are the least similar to each other, the disjointpaths in networkX does not always return two paths in my case and I need exactly two. Answer nx.disjointpaths find…
Do you know how to split a list of strings into different variables?
I am a beginner in python, and I have a question that perhaps is simple. I have a “file.txt”, where in principle there can be a number n of strings. This is loaded into the program with: Now, I load a dataframe from a csv, which has a column (with name “Identifier”) that contains a lot…
Multiple color argument in plotly in python
My objective is make a bar plot in plotly. I did I get I want Type A & Type B to have different colors, and preferable additional separate legend. I tried: but this gives error. Answer Using color to illustrate two different dimensions of your data would, in my opinion, quickly become very confusing. Unle…
Exporting HashMap of HashMap to Python
I have a text parser written in Rust and want to provide a Python interface to it using pyo3. The parser returns a HashMap within a HashMap and the values of the inner HashMap are of type serde_json::Value. When I try to return this as a PyObject I get an error that I am unable to solve. This is a
How can I send a message to a user out of a JSON file?
Probably a very easy question to answer, but I want to send a message to a user after a certain time. For this I read his ID from a JSON. Problem with this? You cannot append a send to a str or this error is then spit out. I have already tried to convert the whole thing, but without success.
Converting dict to DataFrame gives too many rows
I am trying to convert a dict to Pandas DataFrame as the following: And when I print out the DataFrame, I see the following output: I expect to see 1 row only in the DataFrame but it gives 5. And I cannot understand why. What am I doing wrong here? Answer You’re not doing anything wrong. Since tags is a
Fixing points as non-outliers during outlier detection in Python
I found this Scikit Learn page explaining how to use different algorithms to detect outliers: https://scikit-learn.org/stable/modules/outlier_detection.html Is it possible to set a group of instances as non-outliers so that the algorithms understand that those specific points should not be detected as outlier…
The most efficient way to sum all possible pairs (x_ik, y_j) for a given k?
I have two numpy array x with shape (n,m) and y with shape (p,). I would like to sum all possible pairs x[k, i] and y[j] to create a new numpy array z with shape (n, m*p). A naïve algorithm would be : This algorithm has a polynomial complexity : O(n*m*p) Knowing I am working on array with $n ~
In pandas, how to pivot a dataframe on a categorical series with missing categories?
I have a pandas dataframe with a categorical series that has missing categories. In the example shown below, group has the categories “a”, “b”, and “c”, but there are no cases of “c” in the dataframe. The resulting pivoted dataframe has columns a and b. I expect…
How to save some data in user model and some data save in extended user model from a html form
model.py views.py enter image description here I want to save the user name, email, password in the user model and others field wants to save in the UserProfile model. Then want to fetch data like- {{user.UserProfile.phone}} Answer I had the same issue I saved the data using the same method as you did. And no…