Skip to content

Instantly share code, notes, and snippets.

@dboyliao
Created October 10, 2017 13:40
Show Gist options
  • Select an option

  • Save dboyliao/06b0ee9c9921f508bd3ad72cb076d2f4 to your computer and use it in GitHub Desktop.

Select an option

Save dboyliao/06b0ee9c9921f508bd3ad72cb076d2f4 to your computer and use it in GitHub Desktop.
iterate over row in pandas example
#!/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