質問編集履歴

2

差し替え

2019/08/31 12:34

投稿

farinelli
farinelli

スコア61

test CHANGED
File without changes
test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  ### 現状
24
24
 
25
- ![イメージ説明](0f589ae951a1fd3362495b25d886c752.png)
25
+ ![イメージ説明](f9f6d2e79bf39f75dc120c505dc8ff68.png)
26
26
 
27
27
  ### 理想の出力結果
28
28
 
@@ -38,11 +38,7 @@
38
38
 
39
39
 
40
40
 
41
- df = pd.read_csv('renshu.csv', index_col='Name')
42
-
43
- #import pdb; pdb.set_trace()
44
-
45
- df2 = df.loc[:,['One','Three','Five','Two','Four']]
41
+ df = pd.read_csv('renshu.csv', index_col='Name', usecols=['Name','One','Three','Five','Two','Four'])
46
42
 
47
43
 
48
44
 
@@ -54,17 +50,19 @@
54
50
 
55
51
 
56
52
 
57
- for (idx, row), ax in zip(df.iterrows(), axes.ravel()):
53
+ for idx, row in df.iterrows():
58
54
 
59
- score = row.sort_values(ascending=False)
55
+ for ax in axes.ravel():
60
56
 
61
- if score.iloc[0] >= score.iloc[1] * 2:
57
+ score = row.sort_values(ascending=False)
62
58
 
63
- ax.bar(df2.columns, row.values, align="center", width=0.8)
59
+ if score.iloc[0] >= score.iloc[1] * 2:
64
60
 
65
- ax.set_xticklabels(df2.columns, rotation=85)
61
+ ax.bar(df.columns, row.values, align="center", width=0.8)
66
62
 
63
+ ax.set_xticklabels(df.columns, rotation=85)
64
+
67
- ax.set_title(idx)
65
+ ax.set_title(idx)
68
66
 
69
67
 
70
68
 

1

依頼文の改変

2019/08/31 12:34

投稿

farinelli
farinelli

スコア61

test CHANGED
File without changes
test CHANGED
@@ -6,67 +6,27 @@
6
6
 
7
7
  y軸に「最大値」
8
8
 
9
- として表示させたグラフを写真に並べようとしてコードを書いた所、以下のエラーが出てしまいました。
9
+ として表示させたグラフを写真のように並べようとしてコードを書いた所、以下のようになってしまいました。
10
+
11
+
12
+
13
+ やりたい事は以下の2点です。
14
+
15
+ ・if文の条件を満たす行として、A,C,D,E,F,Hのグラフを出力したい
16
+
17
+ ・X軸の「One,Three,Five」「Two,Four」のまとまりを「Odd」「Even」とグループ化したい。
10
18
 
11
19
 
12
20
 
13
21
  解決に向けてお知恵をお貸しいただけますと幸いです。宜しくお願いします。
14
22
 
23
+ ### 現状
15
24
 
25
+ ![イメージ説明](0f589ae951a1fd3362495b25d886c752.png)
16
26
 
17
27
  ### 理想の出力結果
18
28
 
19
29
  ![イメージ説明](78e40a222392945055b5422c6fc78cfc.png)
20
-
21
-
22
-
23
- ### エラー
24
-
25
- ```
26
-
27
- /Users/macuser/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pandas/core/indexing.py:1418: FutureWarning:
28
-
29
- Passing list-likes to .loc or [] with any missing label will raise
30
-
31
- KeyError in the future, you can use .reindex() as an alternative.
32
-
33
-
34
-
35
- See the documentation here:
36
-
37
- https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike
38
-
39
- return self._getitem_tuple(key)
40
-
41
- Traceback (most recent call last):
42
-
43
- File "plot.py", line 42, in <module>
44
-
45
- ax.bar(df2.columns, row.values, align="center", width=0.8)
46
-
47
- File "/Users/macuser/.pyenv/versions/3.7.4/lib/python3.7/site-packages/matplotlib/__init__.py", line 1601, in inner
48
-
49
- return func(ax, *map(sanitize_sequence, args), **kwargs)
50
-
51
- File "/Users/macuser/.pyenv/versions/3.7.4/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 2375, in bar
52
-
53
- np.atleast_1d(x), height, width, y, linewidth)
54
-
55
- File "<__array_function__ internals>", line 6, in broadcast_arrays
56
-
57
- File "/Users/macuser/.pyenv/versions/3.7.4/lib/python3.7/site-packages/numpy/lib/stride_tricks.py", line 264, in broadcast_arrays
58
-
59
- shape = _broadcast_shape(*args)
60
-
61
- File "/Users/macuser/.pyenv/versions/3.7.4/lib/python3.7/site-packages/numpy/lib/stride_tricks.py", line 191, in _broadcast_shape
62
-
63
- b = np.broadcast(*args[:32])
64
-
65
- ValueError: shape mismatch: objects cannot be broadcast to a single shape
66
-
67
- ```
68
-
69
-
70
30
 
71
31
  ### コード
72
32
 
@@ -80,7 +40,9 @@
80
40
 
81
41
  df = pd.read_csv('renshu.csv', index_col='Name')
82
42
 
43
+ #import pdb; pdb.set_trace()
44
+
83
- df2 = df.loc[:,['Name','One','Three','Five','Two','Four']]
45
+ df2 = df.loc[:,['One','Three','Five','Two','Four']]
84
46
 
85
47
 
86
48
 
@@ -102,15 +64,13 @@
102
64
 
103
65
  ax.set_xticklabels(df2.columns, rotation=85)
104
66
 
105
- ax.set_title('Name: %s' % idx)
67
+ ax.set_title(idx)
106
68
 
107
69
 
108
70
 
109
71
  plt.show()
110
72
 
111
73
  ```
112
-
113
-
114
74
 
115
75
  ### ファイル
116
76