查找给定 Pandas 系列中的单词长度
在这个任务中,我们将找到Pandas系列中字符串的长度。为此,我们将使用Pandas库中的函数。str.len()
算法
Step 1: Define a Pandas series of string. Step 2: Find the length of each string using the str.len() function. Step 3: Print the results.
示例代码
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