-5

I have a list of 22000 strings like abc.wav . I want to take out a specific character from it in python like a character which is before .wav from all the files. How to do that in python ?

  • 1
    `df['file'].str.split('.').str[0]` ? – harvpan Jul 12 '18 at 19:07
  • look into .split() – ltd9938 Jul 12 '18 at 19:08
  • 2
    Hi! Welcome to Stack Overflow. You may have noticed that your first post got a few downvotes - don't worry about that. It happens to almost everyone here the first time they post, but you'll get better as you learn. There are two issues I can see with this post, the first one is that you haven't done any research (as @dfundako pointed out). Have you looked online for solutions to your question? If so, where have you looked, and why haven't those solutions worked for you? – Pro Q Jul 12 '18 at 19:17
  • 1
    The second issue I can see is that it's hard to understand exactly what you want. Adding some examples of "here is the input I have" and "here is the output I want" can help people here figure out what you're looking for. – Pro Q Jul 12 '18 at 19:19

3 Answers3

0

finding the spot of a character could be .split(), but if you want to pull up a specific spot in a string, you could use list[stringNum[letterNum]]. And then list[stringNum].split("a") would get two or more separate strings that are on the other side of the letter "a". Using those strings you could get the spots by measuring the length of the string versus the length of the strings outside of a and compare where those spots were taken. Just a simple algorithm idea ig. You'd have to play around with it.

0

I am assuming you are trying to reconstruct the same string without the letter before the extension.

resultList = []
for item in list:
    newstr = item.split('.')[0]
    extstr = item.split('.')[1]
    locstr = newstr[:-1] <--- change the selection here depending on the char you want to remove
    endstr = locstr + extstr
    resultList.append(endstr)

If you are trying to just save a list of the letters you remove only, do the following:

resultList = []
for item in list:
    newstr = item.split('.')[0]
    endstr = newstr[-1]
    resultList.append(endstr)
Jack Walsh
  • 562
  • 4
  • 14
0
df= pd.DataFrame({'something':['asb.wav','xyz.wav']})
df.something.str.extract("(\w*)(.wav$)",expand=True)

Gives:

    0   1
0   asb .wav
1   xyz .wav
mad_
  • 8,121
  • 2
  • 25
  • 40