[英]How do I remove unwanted characters from a list created through python from yfinance?
I am pulling tickers from yfinance into a list and attempting to print the list.我正在将 yfinance 的股票代码拉入一个列表并尝试打印该列表。 When printing, the list prints with characters added to each stock ticker.
打印时,列表打印时会在每个股票代码中添加字符。 I would like to remove these characters and have tried using the
lstrip
and rstrip
functions but I continue to get the added characters.我想删除这些字符并尝试使用
lstrip
和rstrip
函数,但我继续获得添加的字符。 Below is the input code:下面是输入代码:
for i in edited_buylist:
i = str(i)
i = i.lstrip('yfinance.Ticker object <')
for i in edited_buylist:
i = str(i)
i = i.rstrip('>')
print("The list of securities that are at or near support points are: ", str(edited_buylist))
Below is the output of that code:以下是该代码的输出:
The list of securities that are at or near support points are: [yfinance.Ticker object <VVV>]
''' '''
I would like to remove the "yfinance.Ticker object<" and ">".我想删除“yfinance.Ticker 对象<”和“>”。
You can use the ticker
attribute:您可以使用
ticker
属性:
edited_buylist = [i.ticker for i in edited_buylist]
print("The list of securities that are at or near support points are: ", str(edited_buylist))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.