I’m just learning python, and I’m having some problems reading a .txt file that I created. My objective: I have a txt file with a list of strings. I’m trying to read, process it and save every letter into a new list. example2.txt file: [one, two, THREE, one, two, ten, eight,cat, dog, bird, fish] [Alonso, Alicia, Bob, Lynn] , [red,
Tag: split
Pandas Column Split but ignore splitting on specific pattern
I have a Pandas Series containing Several strings Patterns as below: I would like to split and explode it such that the result would be as follows: In order to do the explode I need to first split. However, if I use split(‘,’) that also splits the items between [] which I do not want. I have tried using split
Different lines of input and output in Python
I’m currently trying to solve the max value problem. However, I’m now having a hard time getting many outputs at the same time. I try to use input().splitlines() to do it, but I only get one output. The test case and output need to have many lines just as the box’s examples. If anyone can provide me with some assistance,
Advanced string manipulation in Python
I’m trying to get only the value that are after the string 2021 from the following string: I need to get those 2 values separated (first one has to be 168088000000 and the second one has to be 61271000000 in this case). They have to be preceded by 2021 (and the result should give only the 2 numbers I mentioned
Pandas: Split and/or update columns, based on inconsistent data?
So I have a column that contains baseball team names, and I want to split it into the 2 new columns, that will contain separately city name and team name. Team New York Giants Atlanta Braves Chicago Cubs Chicago White Sox I would like to get something like this: Team City Franchise New York Giants New York Giants Atlanta Braves
how to split a numpy array into subarrays based on values of one colums
I have a big numpy array and want to split it. I have read this solution but it could not help me. The target column can have several values but I know based on which one I want to split it. In my simplified example the target column is the third one and I want to split it based on
Splitting a string within a list into a list of lists and further splitting its elements if special character found
I’ve got a list of strings that I split into a list of list on (‘/>’), yet I want to split the elements of that list within further depending on IF it has a certain character (‘/’) in it while maintaining the order that the ‘further elements’ are split in. So for example Instead of the above, I’m trying to
list index out of range in for loop (2nd iteration)
In my programm I take some data (variable raw) out of a database and have to use it. When using print(raw) this gets displayed: (‘x1 y1 z1 nx2 y2 z2 nx3 y3 z3 nx4 y4 z4’,) (raw has over 450 elements so I shortened it) Now I have to get x1 and y1 and forward them to another module. To
How to extract the value between the key using RegEx?
I have text like: I want to extract the characters as a list between a. For the above text, I am expecting output like: I have used: But it doesn’t work. Answer The ^ and $ will only match the beginning and end of a line, respectively. In this case, you will get the desired list by using the line:
How to keep n characters of each row of a pd df, where n differs by row?
I have created a df one column of which contains string values that I want to trim based on a different int value each time. Ex.: From: length String -3 adcdef -5 ghijkl I wanna get: length String -3 def -5 hijkl What I tried is the following: However, I keep getting this warning: SettingWithCopyWarning: A value is trying to