Last active
May 8, 2019 14:38
-
-
Save ohtomi/602010e38134eed00ee98b4d20136016 to your computer and use it in GitHub Desktop.
PandasのDataFrameを使ってCSVファイルから特定の行をルックアップするサンプル
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
import sys | |
import pandas as pd | |
def main(name): | |
df = pd.read_csv('./sample.csv', header=0) | |
filtered = df[df['token'] == name] | |
if len(filtered.index) > 0: | |
value = filtered.loc[filtered.index[0]]['normalized'] | |
print(value) | |
else: | |
print('Not Found. NAME: ' + name) | |
if __name__ == '__main__': | |
if len(sys.argv) > 1: | |
main(sys.argv[1]) | |
else: | |
print('USAGE: python3 lookup.py NAME') |
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
token | normalized | |
---|---|---|
AUD/JPY | AUD/JPY | |
オージーエン | AUD/JPY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment