Multiple Criteria and Multiple Returns Excel - vba

It's been a while since I've been here. I've been struggling with a formula on Excel using multiple lookups giving multiple returns.
In this sheet, the inputs are:
Location, Subject, Level.
I used the following formula to return the teacher's name in H4:
=INDEX(D2:D26, MATCH(1, (H1=A2:A26)(H2=B2:B26)(H3=C2:C26), 0))
I'm trying to have it return the multiple student IDs.
With the following inputs:
Location Lookup: U
Subject Lookup: QC
Level Lookup: 2
I'm expecting the following student IDs being returned, but I'm not sure of how to solve this.
1012, 1013, 1014, 1015, 1016, 1017, 1018
!
'
Can you please help??
Thank you so much!

Use this array formula in H5 cell to get student IDs and fill down as you need.
=IFERROR(INDEX($E$1:$E$26,SMALL(IF(($A$1:$A$26=$H$1)*($B$1:$B$26=$H$2)*($C$1:$C$26=$H$3),ROW($D$1:$D$26)),ROWS($A$1:$A1))),"")
As it is a array formula, Press CTRL+SHIFT+ENTER to evaluate the formula.

Related

pandas drop row if column contains string

I have a csv file as follow:
message,name,userID,period,#timestamp,timediff
messagebody,Request URL,system,period_8,2021-05-10 09:21:31,1
messagebody,Request URL,system,period_9,2021-05-10 09:58:19,1
"Failed Logon for user ""user""",Logon Attempt,user,period_1,2021-05-10 08:00:22,1
"Failed Logon for user ""user""",Logon Attempt,user,period_1,2021-05-09 05:59:34,1
I am trying to check check the userID and remove all the rows that contains system
I tried with:
f['userID'] = f[~f["userID"].str.contains("system", na=False)]
But it doesn't seem to drop the rows.
Just a little explanation about the columns userID
This column is the result of a merge of other 2 columns.
f['userID'] = f[['destinationUserName','sourceUserName']].astype(str).agg(''.join,1).replace('nan','',regex=True)
f['userID'] = f[~f["userID"].str.contains("system", na=False)]
if I run my script I get this error:
ValueError: Length mismatch: Expected axis has 239 elements, new values have 252 elements
Can anyone help me to understand how to overcome this issue?
How can I target that column and remove specific rows that contains a specific string.
thank you so much for any help

Clean output of a panda data extraction deleting unnamed index column

I have a dataset which have extracted a row under condition in column 'Description'. This is first few rows to show how data look like.
I have extracted a row whith the condition below:
ATL_ID=airport_codes[airport_codes['Description'].str.contains('Hartsfield-Jackson Atlanta ')]
It successfully finds the row. Now, I need to extract the value under 'Code' I use this code:
ATL_ID.loc[:,'Code']
and output is:
373 10397
Name: Code, dtype: int64
I dnt want anything else in the output except 10397. 373 is the row index and the rest is additional description which I dnt want. How I can get one number for the 'Code'?
Thanks

Replacing substrings based on lists

I am trying to replace substrings in a data frame by the lists "name" and "lemma". As long as I enter the lists manually, the code delivers the result in the dataframe m.
name=['Charge','charge','Prepaid']
lemma=['Hallo','hallo','Hi']
m=sdf.replace(regex= name, value =lemma)
As soon as I am reading in both lists from an excel file, my code is not replacing the substrings anymore. I need to use an excel file, since the lists are in one table that is very large.
sdf= pd.read_excel('training_data.xlsx')
synonyms= pd.read_excel('synonyms.xlsx')
lemma=synonyms['lemma'].tolist()
name=synonyms['name'].tolist()
m=sdf.replace(regex= name, value =lemma)
Thanks for your help!
df.replace()
Replace values given in to_replace with value.
Values of the DataFrame are replaced with other values dynamically. This differs from updating with .loc or .iloc, which require you to specify a location to update with some value.
in short, this method won't make change on the series level, only on values.
This may achieve what you want:
sdf.regex = synonyms.name
sdf.value = synonyms.lemma
If you are just trying to replace 'Charge' with 'Hallo' and 'charge' with 'hallo' and 'Prepaid' with 'Hi' then you can use repalce() and pass the list of words to finds as the first argument and the list of words to replace with as the second keyword argument value.
Try this:
df=df.replace(name, value=lemma)
Example:
name=['Charge','charge','Prepaid']
lemma=['Hallo','hallo','Hi']
df = pd.DataFrame([['Bob', 'Charge', 'E333', 'B442'],
['Karen', 'V434', 'Prepaid', 'B442'],
['Jill', 'V434', 'E333', 'charge'],
['Hank', 'Charge', 'E333', 'B442']],
columns=['Name', 'ID_First', 'ID_Second', 'ID_Third'])
df=df.replace(name, value=lemma)
print(df)
Output:
Name ID_First ID_Second ID_Third
0 Bob Hallo E333 B442
1 Karen V434 Hi B442
2 Jill V434 E333 hallo
3 Hank Hallo E333 B442

Error exceptions.IndexError while importing in Odoo products

I'm trying to import 8500 products, and I cut the CSV in files with 1000 rows. Everything goes fine, but when I get 2500, I get this error:
Unknown error during import: : list index out of range at row 2
name,categ_id,standard_price,list_price,Public Price,default_code,description_purchase,Main Supplier,sale_delay,taxes_id,Id. Externo,property_account_expense,route_ids/id,Acabado,product_variant_ids/attribute_line_ids/attribute_id,product_variant_ids/attribute_line_ids/value_ids
Mueble Base Encajonada con Estante Metal,Category / Subcategory,999.00,999.24,999.24,A037073000,MOBILETTO BASE SCATOLATA,Provider,35,IVA 21%,A037073000,400000080,"purchase.route_warehouse0_buy,stock.route_warehouse0_mto",A03,Color,D7
Any idea where is the problem?
This error came because of you are given extra line value compare to columns label.
For example:
You have 16 columns than you must have to give 16 values. If you give 17 values than this type of error will come list index out of range
Situation:
Please recheck columns value it must be same as the number of columns label.

How to access columns by their names and not by their positions?

I have just tried my first sqlite select-statement and got a result (an iterator over tuples). So, in other words, every row is represented by a tuple and I can access value in the cells of the row like this: r[7] or r[3] (get value from the column 7 or column 3). But I would like to access columns not by their positions but by their names. Let us say, I would like to know the value in the column user_name. What is the way to do it?
I found the answer on my question here:
cursor.execute("PRAGMA table_info(tablename)")
print cursor.fetchall()