简体   繁体   English

计算嵌套for循环中的行数

[英]Count number of lines in a nested for loop

I have the following dataframe:我有以下数据框: 在此处输入图片说明

each text look like this: "ALL TEXT IS RELEVANT\\r\\n\\r\\nGood morning, and welcome to the Origin Agritech Limited's Fiscal 2016 Earnings Conference Call. All participants will be in listen-only mode. \\r\\n\\r\\nI would now like to turn the conference over to Bill Zima. Mr. Zima, Please go ahead.\\r\\n\\r\\nThank you, operator. Hello, everyone, and thank you for joining us on today's call. Origin Agritech announced its full year 2016 financial results earlier today. Details about this announcement can be found on the company's website.\\r\\n\\r\\nToday, you will hear from Origin's Chief Executive Officer, Dr. Bill Niebur, who'll address company developments and strategies, followed by the company's Chief Financial Officer, Mr. Shashank Aurora, who will review fiscal 2016 financial results. Dr. Niebur will then conclude the company's remarks by providing commentary on the 2017 business outlook, which will be followed by a question-and-answer session.\\r\\n\\r\\nBefore we begin, I would like to remind you每个文本看起来像这样:“所有文本都是相关的\\r\\n\\r\\n早上好,欢迎参加 Origin Agritech Limited 2016 财年收益电话会议。所有参与者都将处于只听模式。\\r\\n\\r \\n我现在想把会议转交给 Bill Zima。Zima 先生,请继续。\\r\\n\\r\\n谢谢接线员。大家好,感谢您加入我们今天的电话会议。Origin Agritech今天早些时候宣布了 2016 年全年财务业绩。有关此公告的详细信息可在公司网站上找到。\\r\\n\\r\\n今天,您将听到 Origin 首席执行官比尔·尼布尔博士的讲话,他将向公司发表讲话接下来是公司的首席财务官 Shashank Aurora 先生,他将回顾 2016 财年的财务业绩。然后 Niebur 博士将通过对 2017 年业务前景发表评论来结束公司的讲话,随后将提出一个问题问答环节。\\r\\n\\r\\n在我们开始之前,我想提醒你 of our Safe Harbor statement.我们的安全港声明。 Our conference call may include forward-looking statements made under the Safe Harbor provisions of the Private Securities Litigation Reform Act of 1995. Although, we believe that the expectations reflected in our forward-looking statements are reasonable as of today, those statements are subject to risks and uncertainties that could cause actual results to differ dramatically from those projected.我们的电话会议可能包括根据 1995 年《私人证券诉讼改革法案》的安全港条款作出的前瞻性陈述。尽管我们认为我们的前瞻性陈述中反映的预期截至今天是合理的,但这些陈述受制于可能导致实际结果与预测结果大相径庭的风险和不确定性。 There can be no assurance that those expectations will prove to be correct...无法保证这些期望会被证明是正确的......

I want to count the number of lines in each article_text and use it for computation:我想计算每个 article_text 中的行数并将其用于计算:

I thought of doing something like this:我想过做这样的事情:

def doc_sentiment (dataframe):
    score_dict={}
    scores=[]
    number_of_sent=0
    for call in dataframe.article_text:
        for sentence in split_into_sentences(call):
            number_of_sent+=1
            vs=sia.polarity_scores(sentence)
            score_dict.update({sentence: vs['compound']})
            score=sum(score_dict.values())/number_of_sent 

This, however, doesn't work.然而,这行不通。 How can I solve this?我该如何解决这个问题?

so basically you are asking to count with 1 less at each iteration from your inner for loop:所以基本上你要求在内部for循环的每次迭代中少计数 1:

number_of_sent=0
for call in dataframe.article_text:
    for sentence in split_into_sentences(call):
        number_of_sent+=1

    number_of_sent -= 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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