简体   繁体   English

如何从 yfinance 通过 python 创建的列表中删除不需要的字符?

[英]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.我想删除这些字符并尝试使用lstriprstrip函数,但我继续获得添加的字符。 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.

相关问题 如何使用Python从单词列表中删除不需要的字符并将其清除到另一个列表中? - How can I remove unwanted characters from a words list and put them cleared in another list using Python? 如何从创建的元组中删除字符? (Python和appJar) - How can I remove characters from this created tuple? (Python and appJar) 通过for循环从列表中删除不需要的字符 - Remove unwanted characters from a list over a for loop 如何在给定不需要的字符列表的情况下删除字符串? 蟒蛇 - How do I strip a string given a list of unwanted characters? Python Python - 从字符串中删除不需要的字符 - Python - remove unwanted characters from a string 从 python 中的字符串集中删除不需要的字符 - Remove unwanted characters from set of strings in python 如何从python中的字符串列表中去除多个不需要的字符? - How to strip multiple unwanted characters from a list of strings in python? 从 yfinance 中删除评论? - Remove comment from yfinance? 在 Python 中,如何从列表中删除包含某些类型字符的任何元素? - In Python, how do I remove from a list any element containing certain kinds of characters? 如果字符串不包含 Python 中的某些字符,我如何从列表中删除它 - How do i remove a string from a list if it DOES NOT contain certain characters in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM