Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

pandas - Extract text from python list item

I've a python list whose items are as below, I want to extract only the text and remove the 0 and space from the item.

  [['0    Client Name:'],
  ['0    Client ID:'],
  ['0    Industry:'],
  ['0    SEC:'],
  ['0    Industry Sector:']]

So, how to extract only the text from each item? This list was the result of the following loop:

   '''for index,row in df.iterrows():
        if index==0:
            continue
        elif index%2!=0:
            title.append(row.to_string().split(","))'''

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try the following, altough not very clean but gets the job done.

l = [['0    Client Name:'],
    ['0    Client ID:'],
    ['0    Industry:'],
    ['0    SEC:'],
    ['0    Industry Sector:']]

newl = []

for i in range(len(l)):
    newl.append(l[i][0].split("  ")[2])

print(newl)
'''
['Client Name:', 'Client ID:', 'Industry:', 'SEC:', 'Industry Sector:']
'''

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...