Home > database >  Concatenate url dtype: string
Concatenate url dtype: string

Time:10-29

I am trying to concatenate url with a list of string as follows: But I am getting errors... Can anyone help

The code is:

import pandas as pd
import numpy as np
from bs4 import BeautifulSoup as soup
from urllib.request import Request, urlopen

data = pd.read_csv("fornews_list.csv")
data['Symbol'] = data['Symbol'].astype("string")
col = data.head(len(data))
col

clmn = list(col)
for i in col: 
print(col[i])

The list:

0       EVK
1      SGRP
2      CRTD
3      PHCF
4      NXTD
5      GREE
6     AUUDW
7      GROM
8      VECT
9      IMPL
10     CRXT
11     FCUV
12     BKKT
13     NURO
Name: Symbol, dtype: string
url = {"http://finance.com/quote.ashx?t="   col[i].text}
print(url)

CodePudding user response:

Try creating a new column:

data['urls'] = data['Symbol'].apply(lambda x: "http://finance.com/quote.ashx?t="   x)

Or to get only a list with all urls do:

urls = ["http://finance.com/quote.ashx?t="   x  for x in data['Symbol'].tolist()]

Full code:

import pandas as pd
data = pd.read_csv("fornews_list.csv")
urls = ["http://finance.com/quote.ashx?t="   x  for x in data['Symbol'].tolist()]
print(urls)
  • Related