0
考慮下面定義的「b」作爲詞典列表。如何從b(b [1] ['index'] [6])的第二個元素'index'中刪除元素6並將新列表保存到b?從熊貓元素列表中刪除元素
import pandas as pd
import numpy as np
a = pd.DataFrame(np.random.randn(10))
b = [{'color':'red','index':a.index},{'color':'blue','index':a.index}]
輸出:
[{'color': 'red', 'index': Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype='int64')}, {'color': 'blue', 'index': Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype='int64')}]
我試圖np.delete和.pop或.DEL的列表(沒有成功),但我不知道是什麼做的最好方法是什麼?
太謝謝你了。 –
@HamidK如果這解決了你的問題,那麼不要忘記將它標記爲你將來接受的答案。 – SirParselot
如果您想刪除'6'作爲索引標題,則您的解決方案是正確的。不是該熊貓數據系列的第6個元素。如果您有時間以索引爲例,並且您想要刪除它的第六個元素,解決方案將失敗。我投了你的解決方案,但我可能需要在問題中編輯我的示例來指出問題。謝謝 –