Created
October 11, 2017 16:14
-
-
Save victorkurauchi/e9c5dece2766384b3443a340a758a9ef to your computer and use it in GitHub Desktop.
using lambda with python to transform dataset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import re | |
| dataset = sc.textFile("file:///home/cloudera/massa_de_exemplo_wol.txt") | |
| categories = [] | |
| regex = r"(\/[^, z]*\.[a-z]\w)+" | |
| result = dataset.map(lambda line: re.search(regex, line).group(0).split('/')[1]) | |
| # print result | |
| for category in result: | |
| if not category in categories: | |
| categories.append(category) | |
| # print categories |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment