Created
October 10, 2017 13:40
-
-
Save dboyliao/06b0ee9c9921f508bd3ad72cb076d2f4 to your computer and use it in GitHub Desktop.
iterate over row in pandas example
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 python3 | |
| # -*- coding:utf8 -*- | |
| import pandas as pd | |
| data = {"split": ["台灣 世界競爭力", "台灣股票開盤", "台電躺著賺"], | |
| "label": ["positive", "negative", "positive"]} | |
| df = pd.DataFrame(data) | |
| count = 0 | |
| for i, row in df.itertuples() | |
| if "台灣" in row.split and row.label == "positive": | |
| count += 1 | |
| print(count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment