Skip to content
Advertisement

Tag: string

Align strings over a common character

I am looking for a simple, pythonic way of doing this with the minimum calculations and loops. I have a bunch of strings, such as: What I would like to print at the screen is: (where the x are actually spaces, but I could not figure out how to show it with this editor) I am aware of string formatting

Pandas sum() with character condition

I have the following dataframe: I want to use cumsum() in order to sum the values in column “1”, but only for specific variables: I want to sum all the variables that start with tt and all the variable that start with bb in my dataframe, so in the end i’ll have the folowing table : I know how to

Trying to convert input to list

I’m trying to take input from user for 2 points and output the distance. I’m getting stuck on converting the input to a list for the output. I might be thinking about it the wrong way, any help to get me in the right direction is appreciated. Answer You can use a list comprehension to translate the inputs into ints

Printing variables and strings in Python

I am trying to print the following lines : ‘My name is John Smith.’ ‘My name is John Smith, and I live in CHICAGO’ and I live in chicago’ My code below : How can I get the results from the top? Answer Output: My name is john smith, and I live in chicago. I am 25 years old. By

How to retrieve partial matches from a list of strings

For approaches to retrieving partial matches in a numeric list, go to: How to return a subset of a list that matches a condition? Python: Find in list But if you’re looking for how to retrieve partial matches for a list of strings, you’ll find the best approaches concisely explained in the answer below. SO: Python list lookup with partial

What is the difference between str(Series).split() and Series.str.split()?

I wanted to know conceptually why there is difference in output using str(Series).split() and Series.str.split(), when using it on the series object. I was looking to split the date based on the punctuation: the str(Series).split() didn’t give me the desired output while the other method, using Series.str.split() but I heard that using the [dot] accessor is frowned upon. I’ve searched

Advertisement