我有一个 Dataframe ,我需要从列中计算字长 Word
每人 Concept
分别视具体情况而定 Note
专栏。
For each Concept in a df:
if Note contains ("tupi") -> count word length for these Words.
if not -> count word length for others
print (Concept + " tupi " + word_length)
print (Concept + " not tupi " + word_length)
输出应该是这样的:
ANTEATER tupi 5.034
ANTEATER not tupi 4.56
_______
WILD CAT tupi 4.55
WILD CAT not tupi 3.44
输入 Dataframe 示例:
语言概念单词Borrowing note First Antater Tam and Uáyesloan from Tupie第二AntaterãiarúThird Antaterãn fourthat tatãmyeloan from tupififthwild cattamanoys Exthwild catsdfsgyes from Tupiightwild catsdfsgyes loan from tupi
1条答案
按热度按时间eivgtgni1#
您可以完全在pandas中执行此操作,而不需要for循环。
创建列
tupi
这表示Note
列是否包含“tupi”。创建一个
Word Length
列中单词的长度Word
专栏。现在,使用
groupby
并计算每个词的平均字长Concept
有无“tupi”在Note
专栏:根据给定数据生成的 Dataframe :