回答編集履歴
5
変更
test
CHANGED
@@ -130,7 +130,9 @@
|
|
130
130
|
|
131
131
|
df1 = df[df["ポケモン名"].str.contains(name)]
|
132
132
|
|
133
|
-
print(df1)
|
133
|
+
# print(df1)
|
134
|
+
|
135
|
+
print(df1.loc[:, ["ポケモン名","こうげき"]])
|
134
136
|
|
135
137
|
|
136
138
|
|
@@ -138,10 +140,10 @@
|
|
138
140
|
|
139
141
|
df2 = df1[df1["こうげき"] == int(attack)]
|
140
142
|
|
141
|
-
print(df2)
|
143
|
+
print(df2.loc[:, ["ポケモン名","こうげき"]])
|
142
144
|
|
143
145
|
```
|
144
146
|
|
145
147
|
実行例
|
146
148
|
|
147
|
-
![イメージ説明](
|
149
|
+
![イメージ説明](d30409e161a8d2c1aeed3924948bd26a.png)
|
4
追記2
test
CHANGED
File without changes
|
3
追記2
test
CHANGED
@@ -103,3 +103,45 @@
|
|
103
103
|
実行結果
|
104
104
|
|
105
105
|
![イメージ説明](0b1e7ccbb63d46efbbe71e3bcc595418.png)
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
追記2
|
110
|
+
|
111
|
+
```python3
|
112
|
+
|
113
|
+
import csv
|
114
|
+
|
115
|
+
import pandas as pd
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
df = pd.read_csv('pokemon_status_utf8.csv')
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
while True:
|
124
|
+
|
125
|
+
name = str(input("ポケモン名 (例:リザードン) "))
|
126
|
+
|
127
|
+
if name == '':
|
128
|
+
|
129
|
+
break
|
130
|
+
|
131
|
+
df1 = df[df["ポケモン名"].str.contains(name)]
|
132
|
+
|
133
|
+
print(df1)
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
attack = str(input("すばやさ (例: 130) "))
|
138
|
+
|
139
|
+
df2 = df1[df1["こうげき"] == int(attack)]
|
140
|
+
|
141
|
+
print(df2)
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
実行例
|
146
|
+
|
147
|
+
![イメージ説明](96f792ee309fbc1cdced6a052b2a650b.png)
|
2
追記
test
CHANGED
@@ -89,3 +89,17 @@
|
|
89
89
|
- Pandas でデータフレームから特定の行・列を取得する
|
90
90
|
|
91
91
|
[https://pythondatascience.plavox.info/pandas/%E8%A1%8C%E3%83%BB%E5%88%97%E3%81%AE%E6%8A%BD%E5%87%BA](https://pythondatascience.plavox.info/pandas/%E8%A1%8C%E3%83%BB%E5%88%97%E3%81%AE%E6%8A%BD%E5%87%BA)
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
追記
|
96
|
+
|
97
|
+
```python3
|
98
|
+
|
99
|
+
print(df[(df["ポケモン名"] == "リザードン") & (df["すばやさ"] == 100)])
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
実行結果
|
104
|
+
|
105
|
+
![イメージ説明](0b1e7ccbb63d46efbbe71e3bcc595418.png)
|
1
追記
test
CHANGED
@@ -47,3 +47,45 @@
|
|
47
47
|
- Python3 で CSV の読み書きをする方法 – Shift_JIS と UTF-8 対応サンプルコード付
|
48
48
|
|
49
49
|
[https://www.craneto.co.jp/archives/1309/#CSV-3](https://www.craneto.co.jp/archives/1309/#CSV-3)
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
panda で読み込んで、検索するには次のようにします。
|
54
|
+
|
55
|
+
```python3
|
56
|
+
|
57
|
+
import csv
|
58
|
+
|
59
|
+
import os
|
60
|
+
|
61
|
+
import pandas as pd
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
df = pd.read_csv('pokemon_status_utf8.csv')
|
66
|
+
|
67
|
+
print(df.size)
|
68
|
+
|
69
|
+
# print(df[1:2])
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
print()
|
74
|
+
|
75
|
+
# print(df[df["ポケモン名"] == "リザードン"])
|
76
|
+
|
77
|
+
print(df[(df["ポケモン名"] == "リザードン") & (df["タイプ2"] == "ひこう")])
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
実行例
|
82
|
+
|
83
|
+
![イメージ説明](522902dbd42c66bdf39b3ec1dc3b4010.png)
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
参考情報
|
88
|
+
|
89
|
+
- Pandas でデータフレームから特定の行・列を取得する
|
90
|
+
|
91
|
+
[https://pythondatascience.plavox.info/pandas/%E8%A1%8C%E3%83%BB%E5%88%97%E3%81%AE%E6%8A%BD%E5%87%BA](https://pythondatascience.plavox.info/pandas/%E8%A1%8C%E3%83%BB%E5%88%97%E3%81%AE%E6%8A%BD%E5%87%BA)
|