I am making a program with several screens and each one has its own size, so each time I change of screen I must re-size the App. The problem is that, when I change the size of the window, Kivy only increase or reduce the lenght of the right and the bottom sides, not the four sides, so the screen
Tag: python-3.x
How can I extract the nth row of a pandas data frame as a pandas data frame?
Suppose a Pandas dataframe looks like: How can I extract the third row (as row3) as a pandas dataframe? In other words, row3.shape should be (1,5) and row3.head() should be: Answer Use .iloc with double brackets to extract a DataFrame, or single brackets to pull out a Series. This extends to other forms of DataFrame indexing as well, namely .loc
Python finding the common parts of a string throughout a list and removing it from every item
I have a list of file directories that looks similar to this: I am trying to remove the beginnings of the paths that are the same from every list, and then deleting that from each file. The list can be any length, and in the example I would be trying to change the list into: Methods like re.sub(r’.*I’, ‘I’, filepath)
TypeError: expected string or bytes-like object – with Python/NLTK word_tokenize
I have a dataset with ~40 columns, and am using .apply(word_tokenize) on 5 of them like so: df[‘token_column’] = df.column.apply(word_tokenize). I’m getting a TypeError for only one of the columns, we’ll call this problem_column Here’s the full error (stripped df and column names, and pii), I’m new to Python and am still trying to figure out which parts of the
How to check if a string is a palindrome?
I have a code to check whether a word is palindrome or not: If a word is inputted, for example : rotor , I want the program to check whether this word is palindrome and give output as “The given word is a palindrome”. But I’m facing problem that, the program checks first r and r and prints “The given
Preferred way of resetting a class in Python
Based on this post on CodeReview. I have a class Foo in Python (3), which of course includes a __init__() method. This class fires a couple of prompts and does its thing. Say I want to be able to reset Foo so I can start the procedure all over again. What would be the preferred implementation? Calling the __init__() method
Namespaces inside class in Python3
I am new to Python and I wonder if there is any way to aggregate methods into ‘subspaces’. I mean something similar to this syntax: I am writing an API wrapper and I’m going to have a lot of very similar methods (only different URI) so I though it would be good to place them in a few subspaces that
Python – Send item to next page in Word
I am trying to send text to the next page in a .docx file using Python. So far, I have written a some code that will locate a certain word in a .docx file (using python-docx): Now I want to send each occurrence of “Hello” to a new page so that each page in my Word document starts with the
How can one list item have 2 indexes?
Suppose that I write a list: foo=[1,2,3,4,5,6,7,8,9,1] When I try to find out the index of 1 in foo, it comes out to be 0. But I wanted to find the index of the 1 at the last ( it’s expected index is 9 ) so I wrote this simple code that would give me all the indexes of all
Python type annotation for sequences of strings, but not for strings?
Is there a Python type hint that matches lists, tuples and possibly other sequential types, but does not match strings? The issue is that strings are at the same time sequences of strings of length 1 (e.g. individual characters), so they technically match the Sequence[str], but providing a string to a function expecting a list of strings is an error