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

回答編集履歴

2

追記

2021/03/17 05:58

投稿

jeanbiego
jeanbiego

スコア3966

answer CHANGED
@@ -1,4 +1,7 @@
1
- ・円グフ出
1
+ [matplotlib.pyplot.pie](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pie.html)をみると、xに配列を、labelsにベルを入れろとあので、`plt.pie(df_pie=value, labels=label)`を正しく書くと`plt.pie(x=df_pie, labels=label)`になると思います。
2
+
3
+ そして、`ValueError: could not convert string to float: 'conventional'`に関しては、
4
+ ・type列が数値だと円グラフ出る
2
5
  ```python3
3
6
  import pandas as pd
4
7
  import matplotlib.pyplot as plt
@@ -8,7 +11,7 @@
8
11
  plt.show()
9
12
  ```
10
13
 
11
- ・エラー出る
14
+ type列が文字列だとエラー出る
12
15
  というわけで、dataframeのtype列が、文字列のものを指定してしまっているのではないでしょうか。
13
16
  ```python3
14
17
  import pandas as pd

1

追記

2021/03/17 05:58

投稿

jeanbiego
jeanbiego

スコア3966

answer CHANGED
@@ -4,7 +4,7 @@
4
4
  import matplotlib.pyplot as plt
5
5
  df = pd.DataFrame({"type":[10,20]})
6
6
  label = ['conventional','organic' ]
7
- plt.pie(df["type"], labels=label)
7
+ plt.pie(x=df["type"], labels=label)
8
8
  plt.show()
9
9
  ```
10
10
 
@@ -15,7 +15,7 @@
15
15
  import matplotlib.pyplot as plt
16
16
  df = pd.DataFrame({"type":['conventional','organic' ]})
17
17
  label = ['conventional','organic' ]
18
- plt.pie(df["type"], labels=label)
18
+ plt.pie(x=df["type"], labels=label)
19
19
  plt.show()
20
20
 
21
21
  # ValueError: could not convert string to float: 'conventional'