Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 1 year ago. Improve this question this is my code it is a simple passoword generator but when i
Tag: string
Segregate a column data based on regex using pandas
I have a dataframe like as shown below I would like to create 3 new columns val_num – will store ONLY NUMBER values that comes along with symbols ex: 1234 (from >1234) and 1000 (from <1000) but WILL NOT STORE 31 (from 31sadj) because it doesn’t have any symbol val_str – will store only values a mix of NUMBER,symbols,ALPHABETS or
How to create a new list of all the words separating by each word and each line?
I have a text file as : sample.txt What I’ve tried is This results I want the result as: Answer After opening the file, you can use a list comprehension to iterate over lines, and for each line str.split on whitespace to get tokens for each sublist.
Replace string between two strings with duplicate markers in string
I using python and I have a multi-line string like this: I want to replace “adamredsox24” in a large set of these types of strings with a variable (newName) but from set to set the substring will not always be “adamredsox24” at all and will be unknown to me. In other words, the substring in the quotes after the word
Manipulate string to drop columns on pandas
I’m trying to manipulate a list (type: string) to use that list to drop some columns from a dataframe. Dataframe The list is from a dataframe that I created a condition to return columns whose sums of all values are zero: Selecting the columns with sum = 0 Importing the dataframe and turning it into a list: Images from the
class and defining __str__
This is the exercise: Write the special method __str__() for CarRecord. Sample output with input: 2009 ‘ABC321’ Year: 2009, VIN: ABC321 The following code is what I have came up with, but I’m receiving an error: TYPEERROR: __str__ returned non-string I can’t figure out where I went wrong. Answer You’re returning a tuple using all those commas. You should also
New line character not being replaced even after trying many methods
I cannot get this to replicate outside of this file, since if I try it on a string myself it works, but for some reason not in my dataframe. I just want to get rid of the ‘n’ characters in my strings, but its not working, as seen below. I’ve tried the following, with no success Answer Try adding regex=True
Not finding a good regex pattern to substitute the strings in a correct order(python)
I have a list of column names that are in string format like below: Now I want to add df[] with ” ‘ ” to each column name using regex and I did it which does that when the list has (wallet-phone) this kind of string it gives an output like this df[(‘wallet’]-df[‘phone’)]. How do I get like this (df[‘wallet’]-df[‘phone’]),
Compare two strings, count letters in the right position, then count letters contained in word but in wrong position
I’m working on a game where the computer picks a random word from a list. The user then guess the word from input. The application shall then return +1 for every letter in the correct position and +1 for any letter in the word but not in the correct position. It should only count the letter in the right position
How to remove extra spaces from the data which is being entered
I am trying to remove the extra space from the data which is entered as input. I tried using the .strip() condition but it doesn’t remove the extra space of the entered data. the code I wrote to remove extra space Answer These are 3 ways of dealing with spaces you can use according to your needs: 1- the method