私は何とかタプルとしてインデックスを持つシリーズを取得しています。私はタプル[0]の値を削除することによって、単一の文字列としてインデックスを持つシリーズに変換したいと思います。 This is my current outputDesired Output is something like this but in a series formatPython Pandas Seriesタプルデータフレーム
ありがとうございました。
私は何とかタプルとしてインデックスを持つシリーズを取得しています。私はタプル[0]の値を削除することによって、単一の文字列としてインデックスを持つシリーズに変換したいと思います。 This is my current outputDesired Output is something like this but in a series formatPython Pandas Seriesタプルデータフレーム
ありがとうございました。
あなたはstr[1]
でタプルの第2の値を選択する必要があります。
s.index = s.index.str[1]
サンプル:map
と
s = pd.Series([80,79,70],
index=[('total','Mumbai'),('total','Chennai'),('total','Royal')])
print (s)
(total, Mumbai) 80
(total, Chennai) 79
(total, Royal) 70
dtype: int64
s.index = s.index.str[1]
print (s)
Mumbai 80
Chennai 79
Royal 70
dtype: int64
別の解決策:
s.index = s.index.map(lambda x: x[1])
print (s)
Mumbai 80
Chennai 79
Royal 70
dtype: int64
ありがとうございました。これは機能します。私は.str関数を使用していませんでした – Utkarsh
あなたはおそらくに示すデータを含める必要があります将来の死んだリンクを避けるための質問のリンク – Raz0rwire
@ Raz0rwire私はあなたが何を示唆しているかわからない、stackoverflowに新しいです。リンクは機能していませんか?または、質問自体にデータを貼り付けるようにしますか?あなたもこれに返信すると助けになるでしょう。前もって感謝します。 – Utkarsh