python-3.x

Compare a list with the rows in pandas using Cosine similarity and get the rank

大憨熊 提交于 2021-02-08 12:01:22
问题 I have a Pandas Dataframe and a user input , i would require to compare the user input with each of the rows in the dataframe and get the Ranked list of rows in the dataframe based on Cosine Similarties. Department Country Age Grade Score Math India Young A 97 Math India Young B 86 Math India Young D 68 Science India Young A 92 Science India Young B 81 Science India Young C 76 Social India Young B 88 Social India Young D 62 Social India Young C 72 User input : Country Age Grade Score India

Can't figure out how to return a Python dict/Json as xml using Spyne

[亡魂溺海] 提交于 2021-02-08 11:59:31
问题 I have fired up a WSGI application using Spyne for some SOAP services that I'm trying to build. I'm absolutely new to SOAP and Spyne in general and I can't seem to figure out how to return a JSON/Python dict as XML. This is what I've done. class Fruits(ServiceBase): @rpc(_returns=Iterable(Unicode)) def fruitify(self): fruits = {"apple" : "1", "orange" : ["2","3","4"]} return fruits I think the problem lies in the decorator I'm specifying using _returns . I tried reading the docs again and

How to read json folder data using Python?

亡梦爱人 提交于 2021-02-08 11:57:53
问题 I want to get the data of json folders using Python 3.7.2. This is my json file: {"device": [ {"name": "device1", "status": 0}, {"name": "device2", "status": 1}, {"name": "device2", "status": 1} ] } For my project I need following variables: variable of all devices gathered in a list: devices = ["device1", "device1", "device1"] status of devices saved in different variables: status_device1 = 0 status_device2 = 1 status_device3 = 1 It is possible to change the structure of the json file, but

find pattern in matrix made of lists python 3

为君一笑 提交于 2021-02-08 11:55:56
问题 I have a list made of lists, to create a matrix, mostly filled with zeros and some other numbers like this a = [[0,0,0,1,0,0,0,0], [3,0,0,2,1,0,0,0], [3,0,0,0,0,1,0,0], [3,5,0,4,0,0,0,0]] how could I make a function that takes that variable, and find if there is a number repeated 3 times in the diagonals? For example that It returns True because of the 1. I tried to implement a function like this: def find_diagonal(matriz): for x in range(len(matrix)): for for a in range(len(x)): if matriz[x]

KeyError when formatting locals

本小妞迷上赌 提交于 2021-02-08 11:55:52
问题 I'm facing a KeyError I can't explain or understand. I have a notebook, in which I define a variable PREFIX in a cell: PREFIX = "/home/mavax/Documents/info/notebook/log_study" which is simply a path to a folder containing logs, so people using the notebook just need to change the path if they want to execute the code below. Then, later (quite a bunch of cells beneath), I use it, without any problem: for basename in ["log_converted_full.txt", "log_converted_trimmed.txt"]: entries = load_log

Python3 Print Function

孤街浪徒 提交于 2021-02-08 11:55:29
问题 This probably an easy question but I just can't seem to make it work consistently for different permutations. What is the Python3 equivalent of this? print >> sys.stdout, "Generated file: %s in directory %s\n" % (name+".wav", outdir) I've tried print("String to print %s %s\n", file=sys.stdout % (var1, var2)) and print("String to print {} {}\n".format(var1, var2), file=sys.stdout) What is the best way to do this in Python3 now that the >> operator is no more. I know the % () has the be within

Do Python list comprehensions append at each iteration?

主宰稳场 提交于 2021-02-08 11:53:46
问题 I'm trying to understand the performance of list comprehensions in Python, and the trade-offs of using them versus for loops to create lists. One of the known performance costs of using a for loop to append elements to a list is that at each iteration it is O(k) (where k is the length of the list) because the append needs to get to the end of the list to add an additional element. How does this work for list comprehensions? At each iteration does it need to get to the end of the new list to

Accessing static files included in a Python module

此生再无相见时 提交于 2021-02-08 11:51:22
问题 I'm installing my module with pip. The following is the setup.py: from setuptools import setup, find_packages with open('requirements.txt') as f: required = f.read().splitlines() print(required) setup( name='glm_plotter', packages=find_packages(), include_package_data=True, install_requires=required ) and MANIFEST.in: recursive-include glm_plotter/templates * recursive-include glm_plotter/static * When installing, the directories and files seem to get installed: ... creating build/lib/glm

Generate HTML from HTML template in python?

我的梦境 提交于 2021-02-08 11:49:19
问题 I want to design my own HTML template with tags like JSP or Jade and then pass data from python to it and let it generate full html page. I don't want to construct document at python side like with DOM. Only data goes to page and page tempalte decides, how data lays out. I don't want to serve resulting pages with HTTP, only generate HTML files. Is it possible? UPDATE I found Jinja2, but I has strange boilerplate requirements. For example, they want me to create environment with env =

How to get rid of a label once its text has been renamed?

谁说我不能喝 提交于 2021-02-08 11:48:20
问题 So I have a Label where when a button is pressed, it changes the name of the text to display another label below the existing label. It pretty much just prints the same label with a different text on the row below. When the Delete Text button is pressed, it will delete the new label that has been created but how do I delete the label before the new label? I can also only remove the label via destroy and not forget. I tried changing the text of the variable back to what it says on the window