查找给定 Pandas 系列中单词长度
在此任务中,我们将查找 Pandas 系列中字符串的长度。我们将使用 Pandas 库中的 str.len() 函数来完成此任务。
算法
步骤 1:定义一个字符串的 Pandas 系列。
步骤 2:使用 str.len() 函数查找每个字符串的长度。
步骤 3:打印结果。
示例代码
import pandas as pd
series = pd.Series(["Foo", "bar", "London", "Quarantine"])
print("Series: \n", series)
length = series.str.len()
print("Length:\n", length)
输出
Series:
0 Foo
1 bar
2 London
3 Quarantine
dtype: object
Length:
0 3
1 3
2 6
3 10
dtype: int64