Act fast, special offers end soon! Up to $294 is savings when you get Premium today.
Get offer codes

Chapter - "Regular Expression Basics" under Data Cleaning Advanced - Screen 7

Screen Link:
https://app.dataquest.io/m/354/regular-expression-basics/7/accessing-the-matching-text-with-capture-groups

My Code:

tag_5_freq = tag_5_matches.value_counts()
print(tag_5_freq)

What I expected to happen:
As per the instructed output, it should run as -> Series.value_counts()
What actually happened:

When I run this piece of code in mu Jupyter notebook to check, it throws an error - DataFrame doesn't have any method value_counts

Actually, when I corrected the code as below, it ran fine.

tag_5_freq = tag_5_matches[0].value_counts()
print(tag_5_freq)

<!--Enter other details below: -->
1 Like

This is because of the differences in pandas version. in your version Series.str.extract will return a DataFrame
Check Documentation

If you want the returned value to be a Series set expand=False in your Series.str.extract. Recheck the documentation.

Just to know In new pandas version 1.1.0. They have added value_count method for dataframe too.