Python: 根据另一列中的值提取单元格值

Python: Extracting cell values based on value in another column

每当 F 列(蓝色)中的一行中有 # 时,我需要从 D 列(黄色)中提取字符串。我是初学者,正在尝试 Pandas 和 openpyxl 来完成这项任务,但没有成功。哪个更好?
我希望将它们存储起来以便以后访问它们。
另外,使用正则表达式从 H 列(绿色)中提取数字最简单? Link to onedrive with the excel

您可以使用以下代码 select F 列中的所需值。我还假设 H 列在数字

之前有一个“=”符号
import csv
import pandas as pd
from io import StringIO
Excelfile = "file.xlsx"
df = pd.read_excel(open(Excelfile,'rb'), sheetname='Sheet1')
selectstring = df['ColumnD'].where(df['ColumnF'] == '#')
print selectstring

print df['Columnh'].str.split('=')[1]

我认为您首先需要 read_excel,而且似乎首先需要跳过 7 行:

df = pd.read_excel('LTE_KPIs_up.xlsx', skiprows=7)
#print (df)

然后 select 通过 loc with boolean indexing:

print (df.loc[df.Unit == '#', 'KPI name'])
0            UE-triggered ERAB Setup Attempts
1           UE-triggered ERAB Setup Successes
4           MME-initiated ERAB Setup Attempts
5          MME-initiated ERAB Setup Successes
8      eNodeB-initiated ERAB Release Attempts
9                 eNodeB-initiated ERAB Drops
11        MME-initiated ERAB Release Attempts
12                   MME-initiated ERAB Drops
14                 ERAB Modification Attempts
15                ERAB Modification Successes
18                    HO Preparation Attempts
19                   HO Preparation Successes
22            HO Resource Allocation Attempts
23           HO Resource Allocation Successes
26                          Handover Attempts
27                         Handover Successes
33                        EPS Attach Attempts
34                       EPS Attach Successes
37                        EPS Detach Attempts
38                       EPS Detach Successes
40                EPS Authentication Attempts
41               EPS Authentication Successes
43                EPS Security Setup Attempts
44               EPS Security Setup Successes
46                 EMM Identification Attepmt
47               EMM Identification Successes
49              EPS Service Request Attemptss
50              EPS Service Request Successes
52              Tracking Area Update Attempts
53             Tracking Area Update Successes

117       S6a Delete Subscriber Data Attempts
118      S6a Delete Subscriber Data Successes
120                 S6a Notification Attempts
121                S6a Notification Successes
126               S11 Create Session Attempts
127              S11 Create Session Successes
130                S11 Create Bearer Attempts
131               S11 Create Bearer Successes
134                S11 Update Bearer Attempts
135               S11 Update Bearer Successes
138             Modify Access Bearer Attempts
139            Modify Access Bearer Successes
141            Release Access Bearer Attempts
142           Release Access Bearer Successes
144       Downlink Data Notification Attempts
145      Downlink Data Notification Successes
147               S11 Delete Session Attempts
148              S11 Delete Session Successes
150                S11 Delete Bearer Attempts
151               S11 Delete Bearer Successes
154                          Suspend Attempts
155                         Suspend Successes
157                           Resume Attempts
158                          Resume Successes
162                ME Identity Check Attempts
163               ME Identity Check Successes
168           Credit Control Initial Attempts
169          Credit Control Initial Successes
171       Credit Control Termination Attempts
172      Credit Control Termination Successes
Name: KPI name, dtype: object