-3

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

4
  • 1
    What happens when you try and iterate through it? Commented Dec 4, 2019 at 6:40
  • for i in mySer: print(i)? Commented Dec 4, 2019 at 6:43
  • 1
    Does this answer your question? In Python, how do I determine if an object is iterable? Commented Dec 4, 2019 at 7:40
  • @Evan , thanks , it does answer the question! Commented Dec 5, 2019 at 7:16

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.