How do I confirm that a pandas Series
data structure in Python is an iterable?
Asked
Active
Viewed 731 times
-3

charlesreid1
- 4,360
- 4
- 30
- 52

SAF
- 71
- 6
-
1What happens when you try and iterate through it? – khelwood Dec 04 '19 at 06:40
-
`for i in mySer: print(i)`? – Aryerez Dec 04 '19 at 06:43
-
1Does this answer your question? [In Python, how do I determine if an object is iterable?](https://stackoverflow.com/questions/1952464/in-python-how-do-i-determine-if-an-object-is-iterable) – Evan Dec 04 '19 at 07:40
-
@Evan , thanks , it does answer the question! – SAF Dec 05 '19 at 07:16
1 Answers
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