前提
複数のデータベースから、各野菜名ごとにSheet別で振り分けるコードを教えてください。
ここに質問の内容を詳しく書いてください。
(例)
商品番号 商品名 売上個数 売上日 E F G H I J K L
3001524 にんじん 12 2021/5/17 E F G H I J K L
3000487 ピーマン 5 2021/5/18 E F G H I J K L
3005456 ゴーヤー 2 2021/5/19 E F G H I J K L
3000487 ピーマン 5 2021/5/18 E F G H I J K L
3005456 ゴーヤー 2 2021/5/19 E F G H I J K L
3000487 ピーマン 5 2021/5/18 E F G H I J K L
3005456 ゴーヤー 2 2021/5/19 E F G H I J K L
上記データを
ニンジン:ニンジンのsheetにデータ
・・・・・・・・
・・・・・・・・
・・・・・・・・
実現したいこと
1.
for name in names:
name_df = df[df['商品名']==names]
with pd.ExcelWriter('test.xlsx') as wrlter:
name_df.to_excel(wrlter, sheet_name=names)
2・
for i in list(names):
name_df = df[df['商品名']==names[i]]
with pd.ExcelWriter('test.xlsx') as wrlter:
name_df.to_excel(wrlter, sheet_name=names[i])
ここに実現したいことを箇条書きで書いてください。
・1.### 発生している問題・エラーメッセージ
ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_7468/66971210.py in <module>
1 name_df = {}
2 for name in names:
----> 3 name_df = df[df['商品名']==names]
4 with pd.ExcelWriter('test.xlsx') as wrlter:
5 name_df.to_excel(wrlter, sheet_name=names)
~\anaconda3\lib\site-packages\pandas\core\ops\common.py in new_method(self, other)
67 other = item_from_zerodim(other)
68
---> 69 return method(self, other)
70
71 return new_method
~\anaconda3\lib\site-packages\pandas\core\arraylike.py in eq(self, other)
30 @unpack_zerodim_and_defer("eq")
31 def eq(self, other):
---> 32 return self._cmp_method(other, operator.eq)
33
34 @unpack_zerodim_and_defer("ne")
~\anaconda3\lib\site-packages\pandas\core\series.py in _cmp_method(self, other, op)
5500
5501 with np.errstate(all="ignore"):
-> 5502 res_values = ops.comparison_op(lvalues, rvalues, op)
5503
5504 return self._construct_result(res_values, name=res_name)
~\anaconda3\lib\site-packages\pandas\core\ops\array_ops.py in comparison_op(left, right, op)
259 # The ambiguous case is object-dtype. See GH#27803
260 if len(lvalues) != len(rvalues):
--> 261 raise ValueError(
262 "Lengths must match to compare", lvalues.shape, rvalues.shape
263 )
ValueError: ('Lengths must match to compare', (23,), (8,))
・2.### 発生している問題・エラーメッセージ
IndexError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_7468/2792770480.py in <module>
1 for i in list(names):
----> 2 name_df = df[df['商品名']==names[i]]
3 with pd.ExcelWriter('test.xlsx') as wrlter:
4 name_df.to_excel(wrlter, sheet_name=names[i])
IndexError: only integers, slices (:
), ellipsis (...
), numpy.newaxis (None
) and integer or boolean arrays are valid indices
ここにより詳細な情報を記載してください。
あなたの回答
tips
プレビュー