teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

ソース修正

2020/03/27 04:55

投稿

yureighost
yureighost

スコア2183

answer CHANGED
@@ -5,16 +5,16 @@
5
5
  import random
6
6
 
7
7
  file0 = "/Users/apple/Downloads/practice.tsv"
8
- d = pd.read_table(file0)
8
+ d = pd.read_table(file0, index_col='NAME')
9
9
 
10
10
  #'NAME'列をリスト化しそこからランダムで一つ取り出す
11
- random_res = random.choice(list(d.NAME))
11
+ random_res = random.choice(list(d.index))
12
12
  print("Would you like {} ?".format(random_res))
13
13
 
14
14
  user_res = input("yes or no ?")
15
15
  if user_res == "yes":
16
16
  #[random_res,'COUNT']の値に1加算
17
- d.loc[d.NAME == random_res, "COUNT"] += 1
17
+ d.loc[d.index == random_res, "COUNT"] += 1
18
18
  #tsv(タブ区切り)形式でファイルを書き出す
19
19
  d.to_csv(file0, sep="\t")
20
20
  ```

2

ソース修正

2020/03/27 04:54

投稿

yureighost
yureighost

スコア2183

answer CHANGED
@@ -4,7 +4,7 @@
4
4
  import pandas as pd
5
5
  import random
6
6
 
7
- file0 = "data/practice.tsv"
7
+ file0 = "/Users/apple/Downloads/practice.tsv"
8
8
  d = pd.read_table(file0)
9
9
 
10
10
  #'NAME'列をリスト化しそこからランダムで一つ取り出す

1

ソース修正

2020/03/27 04:49

投稿

yureighost
yureighost

スコア2183

answer CHANGED
@@ -4,7 +4,7 @@
4
4
  import pandas as pd
5
5
  import random
6
6
 
7
- file0 = "/Users/apple/Downloads/practice.tsv"
7
+ file0 = "data/practice.tsv"
8
8
  d = pd.read_table(file0)
9
9
 
10
10
  #'NAME'列をリスト化しそこからランダムで一つ取り出す
@@ -14,7 +14,7 @@
14
14
  user_res = input("yes or no ?")
15
15
  if user_res == "yes":
16
16
  #[random_res,'COUNT']の値に1加算
17
- d.loc[d.NAME == random_res, 'COUNT'] += 1
17
+ d.loc[d.NAME == random_res, "COUNT"] += 1
18
18
  #tsv(タブ区切り)形式でファイルを書き出す
19
- d.to_csv(file0, sep='\t')
19
+ d.to_csv(file0, sep="\t")
20
20
  ```