2017-07-18 47 views
0

我有一個像下面[72行×25列]一個數據幀:df.ix得到NAN作爲集

 Pin  CPULabel Freq(MHz) DCycle  Skew(1-3)min Skew(1-3)mean 
0 Dif0 BP100_Fast 99.9843 0.492   0    0 
1 Dif0 BP100_Slow 100.011 0.493   0    0 
2 Dif0 100HiBW_Fast 100.006 0.503   0    0 
3 Dif0 100HiBW_Slow 100.007 0.504   0    0 
4 Dif0 100LoBW_Fast 100.005 0.503   0    0 
5 Dif0 100LoBW_Slow 99.9951 0.504   0    0 
8 Dif1 BP100_Fast 99.9928 0.492   7   10 
9 Dif1 BP100_Slow 99.9962 0.492   11   12 
10 Dif1 100HiBW_Fast 100.014 0.502   10   11 
11 Dif1 100HiBW_Slow 100.006 0.503   6   13 
12 Dif1 100LoBW_Fast 99.9965 0.502   5   10 
13 Dif1 100LoBW_Slow 99.9946 0.503   12   14 
16 Dif2 BP100_Fast 99.9929 0.493   2    6 
17 Dif2 BP100_Slow 99.997 0.493   8   13 
18 Dif2 100HiBW_Fast 100.002 0.504   4    9 
19 Dif2 100HiBW_Slow 99.9964 0.504   13   17 
20 Dif2 100LoBW_Fast 100.021 0.504   8    9 

我在其中包含BP100_Fast,100HiBW和100HiBW串行只是有興趣。所以我用下面的命令:

excel = pd.read_excel('25C_3.3V.xlsx', skiprows=1) 
excel.fillna(value=0, inplace=True) 
general = excel[excel['Pin'] != 'Clkin'] 
general.drop_duplicates(keep=False, inplace=True) 
slew = general[(general['CPULabel']=='BP100_Fast') | (general['CPULabel']=='100LoBW_Fast') | (general['CPULabel']=='100HiBW_Fast')] 

我能夠得到我想要的東西[36行×25列]:

 Pin  CPULabel Freq(MHz) DCycle  Skew(1-3)min Skew(1-3)mean 
0 Dif0 BP100_Fast 99.9843 0.492   0    0 
2 Dif0 100HiBW_Fast 100.006 0.503   0    0 
4 Dif0 100LoBW_Fast 100.005 0.503   0    0 
8 Dif1 BP100_Fast 99.9928 0.492   7   10 
10 Dif1 100HiBW_Fast 100.014 0.502   10   11 
12 Dif1 100LoBW_Fast 99.9965 0.502   5   10 
16 Dif2 BP100_Fast 99.9929 0.493   2    6 
18 Dif2 100HiBW_Fast 100.002 0.504   4    9 
20 Dif2 100LoBW_Fast 100.021 0.504   8    9 

但是,如果我改變了最後的命令:

slew = general.ix[['BP100_Fast', '100LoBW_Fast', '100HiBW_Fast'], :] 

我得到了NAN作爲我的結果。 [3 rows x 25 columns]

   Pin CPULabel Freq(MHz) DCycle Skew(1-3)min Skew(1-3)mean 
BP100_Fast NaN  NaN  NaN  NaN  NaN   NaN 
100LoBW_Fast NaN  NaN  NaN  NaN  NaN   NaN 
100HiBW_Fast NaN  NaN  NaN  NaN  NaN   NaN 

有什麼辦法可以用df.ix來完成這個嗎?非常感謝你。

回答

2

Per Docs

.ix索引器已棄用,有利於更嚴格的.iloc和.loc索引器。 .ix爲推斷用戶想要做什麼提供了很多魔力。換句話說,.ix可以根據索引的數據類型決定在位置或通過標籤進行索引。多年來這已經導致了用戶很多的困惑。完整的索引文檔在這裏。 (GH14218)

選項1
isin

general[general.CPULabel.isin(['BP100_Fast', '100LoBW_Fast', '100HiBW_Fast'])] 

    Pin  CPULabel Freq(MHz) DCycle Skew(1-3)min Skew(1-3)mean 
0 Dif0 BP100_Fast 99.9843 0.492    0    0 
2 Dif0 100HiBW_Fast 100.0060 0.503    0    0 
4 Dif0 100LoBW_Fast 100.0050 0.503    0    0 
8 Dif1 BP100_Fast 99.9928 0.492    7    10 
10 Dif1 100HiBW_Fast 100.0140 0.502   10    11 
12 Dif1 100LoBW_Fast 99.9965 0.502    5    10 
16 Dif2 BP100_Fast 99.9929 0.493    2    6 
18 Dif2 100HiBW_Fast 100.0020 0.504    4    9 
20 Dif2 100LoBW_Fast 100.0210 0.504    8    9 

選項2
query

general.query('CPULabel in ["BP100_Fast", "100LoBW_Fast", "100HiBW_Fast"]') 

    Pin  CPULabel Freq(MHz) DCycle Skew(1-3)min Skew(1-3)mean 
0 Dif0 BP100_Fast 99.9843 0.492    0    0 
2 Dif0 100HiBW_Fast 100.0060 0.503    0    0 
4 Dif0 100LoBW_Fast 100.0050 0.503    0    0 
8 Dif1 BP100_Fast 99.9928 0.492    7    10 
10 Dif1 100HiBW_Fast 100.0140 0.502   10    11 
12 Dif1 100LoBW_Fast 99.9965 0.502    5    10 
16 Dif2 BP100_Fast 99.9929 0.493    2    6 
18 Dif2 100HiBW_Fast 100.0020 0.504    4    9 
20 Dif2 100LoBW_Fast 100.0210 0.504    8    9 

選項3
pd.Series.str.endswith

general[general.CPULabel.str.endswith('Fast')] 

    Pin  CPULabel Freq(MHz) DCycle Skew(1-3)min Skew(1-3)mean 
0 Dif0 BP100_Fast 99.9843 0.492    0    0 
2 Dif0 100HiBW_Fast 100.0060 0.503    0    0 
4 Dif0 100LoBW_Fast 100.0050 0.503    0    0 
8 Dif1 BP100_Fast 99.9928 0.492    7    10 
10 Dif1 100HiBW_Fast 100.0140 0.502   10    11 
12 Dif1 100LoBW_Fast 99.9965 0.502    5    10 
16 Dif2 BP100_Fast 99.9929 0.493    2    6 
18 Dif2 100HiBW_Fast 100.0020 0.504    4    9 
20 Dif2 100LoBW_Fast 100.0210 0.504    8    9 
+0

謝謝,這有助於很多。 – Dogod

2

試試這個辦法:

labels = ['BP100_Fast', '100HiBW', '100HiBW'] 

slew = \ 
pd.read_excel('25C_3.3V.xlsx', skiprows=1) \ 
    .fillna(value=0) \ 
    .query("Pin != Clkin and CPULabel in @labels") \ 
    .drop_duplicates(keep=False) 

或者您可以更改:

slew = general.ix[['BP100_Fast', '100LoBW_Fast', '100HiBW_Fast'], :] 

到:

slew = general.loc[general['CPULabel'].isin(['BP100_Fast','100LoBW_Fast','100HiBW_Fast'])] 
+0

謝謝。它有助於。 – Dogod