gpt4 book ai didi

python - 计算 Pandas 中的行数(换行符)

转载 作者:行者123 更新时间:2023-12-05 09:01:37 26 4
gpt4 key购买 nike

我有一个带有文本列的 pandas datafrme,我想知道如何计算换行符的数量。这就是它在 excel 中的完成方式,现在我想知道如何在 python 中实现它:

How To Count Number Of Lines (Line Breaks) In A Cell In Excel?

最佳答案

你可以试试Series.str.count

df['count'] = df['A'].str.count('\n')
print(df)

A count
0 a\nb 1
1 c\nd\nf 2

关于python - 计算 Pandas 中的行数(换行符),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73009209/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com