简体   繁体   中英

i want to remove sqaure brackets from python list output

 df = pd.read_excel('Websites.xlsx', usecols=[3])
 webs = df.dropna()
 weblist = webs.values.tolist()
 for count in range(0,len(weblist)):
     print (weblist[count])

the output is

['TRIPADVISOR.COM']
['CHASE.COM']
['WEBMD.COM']
['WEATHER.COM']
['INDEED.COM']
['HOMEDEPOT.COM']
['CRAIGSLIST.ORG']
['BANKOFAMERICA.COM']

i need to convert this all to website format like https://www.example.com

I think output is one column Dataframe , so add DataFrame.squeeze for Series, last loop and change url with f-strings :

for i in webs.squeeze():
 print (f'https://www.{i.lower()}')

If I understand what you are intending to do, try flattening list of lists:

flat_weblist = [i for lst in weblist for i in lst]

 ['TRIPADVISOR.COM',
  'CHASE.COM',
  'WEBMD.COM',
  'WEATHER.COM',
  'INDEED.COM',
  'HOMEDEPOT.COM',
  'CRAIGSLIST.ORG',
  'BANKOFAMERICA.COM']

Then joining string:

http_list = [''.join(('http://www', i.lower()) for i in flat_weblist]

['http://tripadvisor.com',
 'http://chase.com',
 'http://webmd.com',
 'http://weather.com',
 'http://indeed.com',
 'http://homedepot.com',
 'http://craigslist.org',
 'http://bankofamerica.com']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM