-3

How do I confirm that a pandas Series data structure in Python is an iterable?

charlesreid1
  • 4,360
  • 4
  • 30
  • 52
SAF
  • 71
  • 6

1 Answers1

0

You can use a try/except block:

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

or

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

# 1 is not iterable
oppressionslayer
  • 6,942
  • 2
  • 7
  • 24