Questions tagged [python]

Python is a multi-paradigm, dynamically typed, multipurpose programming language, designed to be quick (to learn, to use, and to understand), and to enforce a clean and uniform syntax. Two similar but incompatible versions of Python are commonly in use, Python 2.7 and 3.x. For version-specific Python questions, use the [python-2.7] or [python-3.x] tags. When using a Python variant (i.e Jython, Pypy, etc...), please also tag the variant.

0
votes
0answers
4 views

Python - How to ensemble for a multiclass models with only their probabilities?

I have a dataset of 50 classes which I want to make predictions for. The script is run by another party and I was only given an ndarray their predicted probabilities of the classes. i.e. a dimension ...
0
votes
1answer
11 views

My min(list) function is producing the wrong output and I do not know why

I am running a very basic program to find the min/max value of a list I generated, and I am getting the wrong output, but do not know why. I am attaching screenshots which show the output. Although ...
0
votes
0answers
3 views

How can I parse CSV file while preserving dictionary values within rows

*If anyone has suggestions on how to format this better I am more than willing to do so. This is for a homework assignment, the end goal is to normalize the data and insert into a schema that is in ...
-1
votes
0answers
14 views

why does this function return non negative numbers?

In [20]: def relu(x): ...: return (x>0) * x ...: Is that because in Python, True is interpreted as 1 while False as 0 implicitly?
0
votes
0answers
2 views

How to fix errors in singly linked list method append

I have two class a node and a linked. My error is coming from the append method located in the linkedList class. I try to .append(10) but it does not print the 10 out only the 5 when it should be ...
0
votes
0answers
3 views

An algorithm for creating a corner image of an image is simulated and the result is incorrect

An algorithm for creating a corner image of an image is simulated and the result is incorrect。 The sobel_dir operator of HALCON software will return a direction Angle image. I used Python to ...
0
votes
0answers
5 views

Identify possession phrases and the object being possessed by another object in python3

Is there a way to identify the object being possessed by another object in python3 using nlp libraries. For example, "The beautiful dog of Bob", "Bob's beautiful dog", should both return beautiful dog ...
0
votes
1answer
11 views

Python function that takes the name of another Python function as an argument

I would like to define a general function that calls another python function. I wrote the general function that takes the path to another python function and the name of another python function as ...
0
votes
0answers
6 views

regex replace whole string with http with blank

lets say I have a string string ="Today is going well the dog jumped over the fence. The fence was my neighbors asdkhttps://www.urldefence.org/ult/sdfo/90nf3f/lknfksjdn? >>>09sdkfjnkbIAS(...
0
votes
0answers
7 views

Displaying pandas dataframe in QML

I have 2 pandas dataframes, one with 6 rows and 7 columns and another one with 21 rows and 12 columns, i would like to display them using QML, while googling i got to know about TableView TableView ...
-2
votes
1answer
14 views

Instances of Classes --> Method Overwrite Problem

person1 = Person("Michael") person2 = Person("Johnny") So basically, I have two instances of a class called Person. I have no issues with this, they are created successfully. I want to set their age ...
0
votes
2answers
11 views

How to get values on one dataframe based on the position of a value in other dataframe

I have two dataframes with the same size. df1 1 5 3 6 5 1 2 4 9 df2 a b c d e f g h i I want to get the corresponding value on df2 that is in the same position as the maximum value of each row in ...
0
votes
1answer
15 views

How To Delete A csv file upon Exit of Python Operation

I'm trying to make a Python script that reads from a csv file. Upon exit of the Python script or when the Python program is killed or terminated, I want it to delete the csv file that it was reading. ...
0
votes
0answers
10 views

Requests module is not working with cx_freeze

I wrote a script in Python 3.7 to extract information from a website. For this script, I used the following packages: PyQt5, requests, Beautiful Soup, unidecode and os. I need to share this ...
-2
votes
0answers
13 views

So, I want to turn a servo motor left and right

I have a servo motor. And I want to control it using a Raspberry Pi 3B. I don't know how can I make the code for it. For example if I want the servomotor to turn right, I'll push the right arrow key. ...
0
votes
1answer
17 views

Python dataframe rows contains multiple list of string search

I have a list of elements in string format that I want to search in each row and delete others. Below code is working however, it is replaced the search from the last element of the list. I am trying ...
-2
votes
0answers
11 views

How can I apply SMOTE to text classification using Python? and why the accuracy is changing?

I am trying to solve the problem of imbalanced dataset using SMOTE in text classification while using TfidfTransformer and K-fold cross validation. I want to solve this problem by using Python code. ...
0
votes
1answer
7 views

vs-code MS Python extension can't find autopep8 on Linux

Debian Stretch (9) Extension: https://github.com/Microsoft/vscode-python About VS Code: Version: 1.32.3 Commit: a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4 Date: 2019-03-14T23:38:49.842Z Electron: 3.1....
0
votes
0answers
10 views

How to plot graph consisted of line segments between two points using matplotlib

I have network edges defined between 4 points, as : edges = [(2, 5), (2, 4), (2, 3),(3, 5),(3, 4),(3, 2),(4, 5),(4, 4),(4, 2),(4, 3),(5, 4),(5, 2),(5, 3)] I want to plot a graph using these edges. ...
0
votes
1answer
10 views

Cannot Understand Some Errors in __add__ functions

When I study the Class in Python. I met the problems as followed: 1. class Try_int(int): def __add__(self, other): return int(self) + int(other) 2. class Try_int(int): def ...
0
votes
1answer
25 views

Replacing items in a list with items from another list

I'm trying to create a calculator for a User's weighted GPA. I'm using PyautoGUI to ask the user for their grades and type of class they're taking. But I want to be able to take that User input and ...
0
votes
0answers
25 views

Alternates to indexing a string

im quite new to python and im wondering if anyone could help me. I found this piece of code and would like it to work as a string. Thanks import random def checkLetter(letter, word, guess_word): for ...
-1
votes
0answers
9 views

Is there a download listener for Gmail API? (Python)

I'm making a small test program in python, and I'm trying to figure out when a gmail user clicks downloads for downloading an attachment. Is there a download listener or any other way to catch when a ...
0
votes
0answers
6 views

How does python's watchdog module use the File Event Handler class to count the number of newly generated files?

I can print out the newly created file path using on_created method, but it seems to be a circular form of traversing the output one by one. I wonder if I can count it, or treat it as a tree, only get ...
0
votes
0answers
14 views

Is there a better way to average two temperature sensor inputs?

I'm building an overhead console for my car. I want to display the temperature outside using the average reading from two temp sensors. I am currently using Timo's Library and am able to retrieve ...
0
votes
0answers
8 views

How should I update the title of imshow in animation? [duplicate]

I would like to update the title of imshow in animation. I searched this online, but only found solutions for function animation. Here is my code import matplotlib.animation as animation import ...
1
vote
2answers
15 views

Numpy: Combine list of arrays by another array (np.choose alternative)

I have a list of numpy arrays, each of the same shape. Let's say: a = [np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), np.array([[11, 12, 13], [14, 15, ...
0
votes
0answers
7 views

how to run foreachRDD with arguments inside a for loop

I have a for loop creating kafka DStreams by iterating over a list of topic names. Then I want to apply a function to each RDD, but I need to pass the topic name into the function. What I am seeing ...
-1
votes
2answers
16 views

I have to code a linear search but my code doesn't seem to work

I need to write a code that does linear search on a character within a sentence. I have to do it without using any inbuilt functions. The program should output what position the character is in the ...
0
votes
2answers
29 views

Shuffle only the last element of a list

I'm writing a poker engine that draws from a large number of decks and creates many hands. I wanted to make each hand contain only unique cards, so I implemented a duplication check when creating ...
-4
votes
1answer
32 views

i cant sum the numbers (python)

Write a shell (text-based) program, called sum_num.py, that asks the user for a semicolon (;) separated list of numbers, and calculated the total. See the example below. a = str(raw_input("Enter ...
1
vote
1answer
15 views

Any way to create pandas dataframe by parsing/splitting list of urls?

I want to create pandas dataframe from list of urls where I want to split each url by hierarchy and create new columns for it. More specifically, I want to break up url by domain, protocol, query, ...
0
votes
0answers
14 views

Python - Enforce specific method signature for subclasses?

I would like to create a class which defines a particular interface, and then require all subclasses to conform to this interface. For example, I would like to define a class class Interface: def ...
0
votes
0answers
12 views

SQlite delete query not working despite no errors

I have SQLlite table set up as follows: name = List tablename = namesOfTests two columns = testNames and dueDate Please see link - https://sqliteonline.com/#fiddle-5c958b0c1ef9b54xjtktalx6 My ...
0
votes
1answer
13 views

Binary column correlation with numeric column

Is that possible to check correlation between binary column and numeric column in Python, when data are contained in DataFrame? Is there any dedicated functionality to do this?
1
vote
0answers
11 views

How can I reference the environment variables set in DockerHub's UI within my Python application?

I have used DockerHub's UI to set two environment variables, both API keys, so that way I can use automatic builds and not have my API keys available publicly in GitHub. I am attempting to access them ...
-1
votes
0answers
20 views

How are these two lines evaluated step by step? [duplicate]

I came across this on the internet, and didn't quite understand how exactly it's evaluated to give the output identical to the code. s ='s = %r\nprint(s%%s)' print (s%s)
2
votes
3answers
24 views

How can I index a single value from a list containing sublists in python?

As an example, right now I have a list of: list = [[1276, 'c'], [910, 'b'], [819, 'o'], [759, 'z'], [699, 'l']] and I would like to index this list for only a specific letter, for instance: index = ...
0
votes
5answers
32 views

How can I print more than one variable in my print function(Python)?

I'm brand new to python and my teacher showed me an example on how to write multiple variables in a print function but I am getting a syntax error. Did I write it wrong? How can I fix this? def ...
0
votes
0answers
9 views

How to add nodes with a different color to an existing graph with networkx?

I am trying to add and plot other nodes to an existing graph with networkx. I tried different things but got always an error (especially networkx.exception.NetworkXError: Node 0 has no position) I ...
-2
votes
2answers
26 views

Insertion Sort problem — How do I loop through every number?

I wrote an insertion sort, but it doesn't sort all the numbers. When I take out ' y = x - 1 ' and just put ' x - 1 ' in there on it's own, the algorithm works. With the variable, the algorithm doesn'...
0
votes
0answers
8 views

More precise image placement possible with openpyxl? (Pixel coordinates instead of cell coordinates?)

I'm attempting to replicate and automate a well used practice in work: I'm trying to place multiple images and text within a cell in openpyxl, however I can only anchor images to the top left of a ...
0
votes
0answers
6 views

Creating Data Frame From Database Query in Python

I am very new to python and after reading several articles online I am not sure how to proceed. I have a 3.56 gig CSV file that I am trying to subset into multiple data frames using the pandas and ...
0
votes
1answer
20 views

How to find the rest of list after combinations

Could you please help me with this situation? I have 3 lists. list1 = [ "a", "b", "c", "d"] list2 = ["x", "y", "z"] list3 = [1, 2, 3, 4, 5, 6, 7] First, I need to take 3 element of list1, 2 ...
0
votes
0answers
16 views

How to plot timestamps every 15th minute - Matplotlib

I am trying to format the x-axis so that every 15th minute is plotted. Rather than plot every timestamp. I have attempted this via the following but cannot get the timestamps to appear. import pandas ...
0
votes
0answers
5 views

Python SignalR Client Application - How to get the ConnectionId after connection to SignalR Hub

First time poster. This is my first experience developing a microservice using .NET. Clients will use a REST API to request the service, the API will use the microservice to get results and send back ...
-1
votes
1answer
14 views

How do i drop all columns that include '_id' - Python

I have a dataframe with 247 columns. Many of the column names contain "_id" in the column name. How do I drop all columns that contain "_id"??
1
vote
0answers
16 views

How to redirect to new ID of a url

I'm using flask form. When i run the code below to paste the new data to test.html, it returned the url of '/team1/test/[0]' but not '/team1/test/1'. Please help. Thanks. @application.route('/team1/...
0
votes
0answers
19 views

Why should I “use inline comments sparingly”?

Reading PEP8 (https://www.python.org/dev/peps/pep-0008/#comments), I see that programmers should "use inline comments sparingly". No reason for this is provided, though. I wonder why. I really find ...
-1
votes
0answers
22 views

How can I plot this? I'm not exactly sure where to start

I need tornadoes within three hours of a certain observation, but I'm not sure what code I need to enter. temp_buf = 3 start_dtime = hurr_time end_dtime = hurr_time + datetime.timedelta(hours=3) ...

http://mssss.yulina-kosm.ru