我想格式化一系列字符串,以便索引位於字符串中。示例系列: ser = pd.Series(['CT', 'NY', 'MT'], index=['Jessica', 'Eric', 'Toby'])
ser
Jessica CT
Eric NY
Toby MT
dtype: object
所需的輸出:這個 Jessica Jessica: CT
Eric Eric: NY
我試圖使用熊貓來將地圖和過濾器操作鏈接在一起。 我遇到幾個選項,在這裏列出一部分: Pandas How to filter a Series 總之, s = Series(range(10))
s.where(s > 4).dropna()
s.where(lambda x: x > 4).dropna()
s.loc[s > 4]
s.loc[lambda x: x > 4]
舉一個簡單的pd.Series: #create the multiindex and data
mult = pd.MultiIndex.from_product([[1,2,3],[1,2,3]],names=['factor1','factor2'])
data = np.arange(1,4)*np.arange(1,4)[:,np.newaxis]
#create the ser