On this page, a piece of code is already provided in which one column of a dataframe is extracted as a ‘list’. Unless I missed or forgot something, this came as a surprise to me (as something new), since so far extracting a column from a dataframe just resulted in a ‘series’. So I am wondering why here suddenly this is converted to a list. And when I tried it out, actually things still worked when I did not do that conversion.
import re #titles = hn["title"].tolist() # THIS LINE: ORIGINAL CODE BY DATAQUEST titles = hn["title"] # THIS LINE: MY CODE #FROM HERE ON: MY CODE TO COMPLETE THE EXCERCISE python_mentions = 0 pattern = r"[Pp]ython" for a_title in titles: if re.search(pattern, a_title): python_mentions += 1 print (python_mentions)
What I expected to happen:
So in a way, I expected this to fail… as I left out the conversion to list which was added by Dataquest.
What actually happened:
It still works.
So that makes me wonder: why the conversion to a list?