Skip to content

Instantly share code, notes, and snippets.

@juanarrivillaga
Last active January 27, 2021 04:38
Show Gist options
  • Save juanarrivillaga/de0b3ba1ed641b0c3f926217222b53bd to your computer and use it in GitHub Desktop.
Save juanarrivillaga/de0b3ba1ed641b0c3f926217222b53bd to your computer and use it in GitHub Desktop.
import pandas as pd
df = pd.read_csv('en_bigram.csv')
st = df[df["right"] == "some_text"]["left"]
st[st.str.startswith("My")].to_list()
# using a dict reader
import csv
result = []
with open("en_bigram.csv") as f:
reader = csv.DictReader(f)
for row in reader:
if row["right"] == "some_text" and row["left"].startswith("My"):
result.append(row["left"])
# alternatively, using a regular reader if you know the header:
import csv
result = []
with open("en_bigram.csv") as f:
reader = csv.reader(f)
next(reader)# skip-header
for left, right in reader: # assuming you know the header
if right == "some_text" and left.startswith("My"):
result.append(left)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment