首页 > 解决方案 > python中的系列数据结构是可迭代的吗?

问题描述

如何确认SeriesPython 中的 pandas 数据结构是可迭代的?

标签: pythonpandas

解决方案


您可以使用 try/except 块:

import pandas as pd
series = pd.Series(['One'])  
try: 
     iter(series) 
     print('your object is iterable') 
except TypeError: 
     print(series, ' is not iterable') 

# your object is iterable

或者

series = 1  
try: 
     iter(series) 
     print('your object is iterable') 
except TypeError: 
     print(series, ' is not iterable') 

# 1 is not iterable

推荐阅读