実行環境:
Python 3.8.8
OpenCV 4.5.3
です。
イメージとしては、
ser00 = pd.Series([0, 0, 0, 0], index=['a','b', 'c','d'])
df = pd.DataFrame(columns=['key0', 'x0', 'x1', 'ser00'])
s = pd.Series(['K0', 1, 2, ser00], index=df.columns )
df = df.append(s, ignore_index=True)
という感じのを作って、下記のようなことをやりたいです。
- 1行丸ごと書き換え
イメージ:df.loc["key0",:] = [0, 1, 2, [0, 0, 0, 0] ]
や、 - dfの4番目の要素で、
a) 特定の場所('a'の部分だけ、など)に値を入れる
b) ser00の部分のみを丸ごと書き換え
というような感じのことをしたのですが、どうしたらよいのでしょうか?
ちなみに、1では、
VisibleDeprecationWarning: Creating an ndarray from ragged nested
sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays
with different lengths or shapes) is deprecated. If you meant to do
this, you must specify 'dtype=object' when creating the ndarray.
return asarray(a).ndim
というのが出ています。
よろしくお願いします。
df.loc[df.key0=='K0'] = np.array([0, 1, 2, [[0, 0, 0, 0]]], dtype=object)
参考:pandasの dataframeに列を追加し、リストの要素をセットする方法を教えてください]