Category "python"

LabelEncoding a permutation of combination of columns

I'd like to create class labels for a permutation of two columns using sklearn's LabelEncoder(). How do I achieve the following behavior? import pandas as pd im

Python requests library - POST requests takes too long

I have a problem with the python requests library. I try to send a simple POST request to my Keycloak server, to introspect an access token. I tested in in Post

How to use recursion to sum up a list of numbers up until a certain index

I have to write a code that makes use of recursion to sum numbers in a list up until the index is equal to a pre-determined integer value. i.e. list = [1,4,8,

(Pandas, Python) Selecting indices of a parent DF based on shared column values with a child DF

(I recently asked this question on r/learnpython (here), but didn't get any feedback, so am re-posting it verbatim here. Hope that is okay!) Suppose I have a D

KSQL Rest INSERT not inserting

I have created a KSQL table with the following command: ksql> CREATE TABLE CUSTTABLE (id INT PRIMARY KEY, name VARCHAR, purchase VARCHAR) WITH (KAFKA_TOPIC =

Getting bytes written to SQL database for integer column, want integer to be written

I am writing data from a dash app to a SQL database setup by Django and then reading back the table in a callback. I have a column that the value should either

Python rank: give negative rank to negative numbers

I have a basic set of data like: ID Value A 0.1 B 0.2 C -0.1 D -0.01 E 0.15 If we use data.rank() we get the result: ID Value A 3 B 5 C 1 D 2 E 4 Bu

Field value not persisted after import

Model.py class Order(models.Model): customerID = models.CharField(max_length=300, blank=True, null=True) osm_bol = models.CharField(max_length=300, bla

Filter column list based on another column in Python

In Python, I have a dataset like this below, where column1 and column2 are objects and not strings: data = {'id': ['first_value', 'first_value', 'second_value'

Django template language how to fix

Hi I'm trying to build a simple django app but I can't get index.html file to recognise the variables created in views.py. Nothing I do seems to work. Does it h

Name 'model' is not defined

When I input this code print(cross_val_score(model, X, y, cv=3)) An error comes back that reads name 'model' is not defined: print(cross_val_score(model, X, y

Not all edges showing in AtlasView NetworkX

I have the following network graph. # Create the graph with unique edges to check the algorithm correctness G = nx.MultiGraph() G.add_edge('A','B',route='56BM',

Porting python PKCS1_v1_5 encryption code to java but java code not work

I have a backend,which receives codes and returns true or false. I send it codes using my python encryption,it returns true(the result varible): from Cryptodome

Why i'm getting the following error? ValueError: invalid literal for int() with base 10: ''

Here is the code from time import sleep import keyboard # Condição de partida da máquina while True: if keyboard.is_pressed('ENTER'):

how to plot 2d condition function

I want to plot a 2d condition function, and the code as below: from numpy import exp,arange from pylab import meshgrid,cm,imshow,show def z_func(x,y): zPar

Capitalize specific indices of string using awk or python

I have an input file where each line contains 99 lowercase letters, bccdddcdccddddddabcdabcabdbacbdcaaccbbcabacbccabcacbcdcccbdbacdcbbcbcbcccacadaaccababadbcbaa

Handle many models using graphene in django

In my django project i have many different models which i want to query using GraphQL. For instance: class Country(): name = CharField(max_length=255) clas

Framerate affect the speed of the game

I am practicing on pygame and I was wondering how can we do so that the framerate does not affect the speed of execution of the game I would like FPS to not be

Validate user input with data in .txt file

I have searched and searched and tried everything. I am creating a game where the user will input a pre-assigned pin and I want to validate that pin against a

Xarray: grouping by contiguous identical values

In Pandas, it is simple to slice a series(/array) such as [1,1,1,1,2,2,1,1,1,1] to return groups of [1,1,1,1], [2,2,],[1,1,1,1]. To do this, I use the syntax: