looking to split out an excel row into 1 line per option - excel

I have an excel sheet where I have a record containing a travel request, but I need to process this out so I can see all the combinations I need to book.
The original record entry looks like this
ID Family Father Mother Children Destinations
KT1 Smith John Joan John,Mary London,New York
and I need the final result to look like this
ID Family Father Mother Children Destinations
KT1 Smith John Joan John London
KT1 Smith John Joan Mary London
KT1 Smith John Joan John New York
KT1 Smith John Joan Mary New York
(there may be multiple entries under any of the Children and destinations , and possibly other fields which would be needed as well )
I am really unsure of how to do this and would love some advice

Use PowerQuery.
Google its usage and where to find it if you're not familiar, a quick search will produce a lot of results ...
https://www.howtoexcel.org/power-query/the-complete-guide-to-power-query/
https://support.microsoft.com/en-us/office/create-load-or-edit-a-query-in-excel-power-query-ca69e0f0-3db1-4493-900c-6279bef08df4
From there, you can transform your data.
That will achieve your outcome with little to no fuss.

Related

Is it possible to search for two dataframe columns's values in another dataframe's column and return an ID where there are matches?

I have two datasets. One has survey information and the other one has complaints. I am trying to see if the people who took surveys are mentioned in the description of the complaint. There is a column for first and last name in the survey df. My intention is to use a contains function to check the complaints description column for a match on the first and last name. I would then like to add the survey id to the complaints dataset where there is a match.
Survey data:
survey_id
first_name
last_name
survey1
John
Smith
Complaint Data:
complaint_number
description
complaint1
John Wick is a great movie
complaint2
Jason Smith stinks
complaint3
John Smith is awesome!
Expected Result of the new complaint df:
complaint_number
Description
matches
complaint1
John Wick is a great movie
complaint2
Jason Smith stinks
complaint3
John Smith is awesome!
survey1
This assumes exact match on first and last as full name (see new 'pattern' column), and doesn't look to see if two full names are in the description, but this is a start if you need to modify it.
import io
d1 = '''survey_id first_name last_name
survey1 John Smith
survey2 John Wick
'''
df_survey = pd.read_csv(io.StringIO(d1), sep=' \s+', engine='python')
df_survey
d2 = '''complaint_number description
complaint1 John Wick is a great movie
complaint2 Jason Smith stinks
complaint3 John Smith is awesome!
complaint4 John Wick is awesome!
'''
df_complaints = pd.read_csv(io.StringIO(d2), sep=' \s+', engine='python')
df_survey['pattern'] = df_survey.apply( lambda x: ' '.join([x['first_name'], x['last_name']]), axis=1)
df_complaints['matches'] = ''
def find_matches(x):
sid = x['survey_id']
# print(sid, x['pattern'])
df_complaints['matches'].loc[df_complaints['description'].str.contains(x['pattern'], case=False)] = sid
return None
df_survey.apply(lambda x: find_matches(x), axis=1)
df_complaints
Output
complaint_number description matches
0 complaint1 John Wick is a great movie survey2
1 complaint2 Jason Smith stinks
2 complaint3 John Smith is awesome! survey1
3 complaint4 John Wick is awesome! survey2

Split Names in Excel using multiple characters

I've had some luck modifying formulas I've found on this site to separate names in a spreadsheet but I need some help. Can anyone suggest the best way to achieve my goal?
I have a "Tenant" column where each row contains from 1 -5 names, separated by commas and "&".
My data is pretty consistent so there is no need for error routines and it looks like these examples with the max # names being 5:
John Doe, Mary Smith, Rachel Reyes & Ben Thompson
or
John Doe & Mary Smith
or
John Doe, Mary Smith & Rachel Reyes
What I really want to do is separate each name into it's own column and then separate each first name into a another column. I would have a total of 5 columns for full names and 5 more for first names for up to 5 max names if that makes sense.
So for this data: John Doe, Mary Smith, Rachel Reyes & Ben Thompson
Column:
|A|B|C|D|E|F|G|H|I|J|
John Doe|John|Mary Smith|Mary|Rachel Reyes|Rachel|Ben Thompson|Ben|
Any help is appreciated.

Formula for helper column(s) that determines singular or combined values

I am creating helper columns to assist me in reviewing our data, but I am running across an issue with one. What I am trying to accomplish is to create a helper column that tells me, by month, what type of medications a person is prescribed, and then combines multiple selections for the same name into a new name.
A sample data set would be:
A B C
1/1/2016 Doe, John Oral
1/1/2016 Doe, John Compound
1/1/2016 Doe, John Oral
2/1/2016 Smith, Jane Oral
2/1/2016 Smith, Jane Oral
2/1/2016 Adams, Tom Compound
2/1/2016 Doe, John Oral
So, for example, if John Doe was prescribed 2 oral medications and 1 compounded medication on 1/1/2016, the helper column would sort out that the three medications belong to the same person and are of two different types, so changes them to Combined. It would end up something akin to "1-Doe, John-Combined", displayed here:
D
1-Doe, John-Combined
1-Doe, John-Combined
1-Doe, John-Combined
2-Smith, Jane-Oral
2-Smith, Jane-Oral
2-Adams, Tom-Compound
2-Doe, John-Oral
So far, all I have is the concatenation by month:
=MONTH(A2)&"-"&B2&"-"
But I am not certain how to tackle the portion of the formula that will present the type of medication and combine (if required). Also, if necessary, more than one column can be created.
Thank you in advance.
Use SUMPRODUCT to test:
=MONTH(A1) & "-" & B1& "-" & IF(SUMPRODUCT((MONTH($A$1:$A$7)=MONTH(A1))*($B$1:$B$7=B1)*($C$1:$C$7<>C1))>0,"Combined",C1)

Extract list in excel based on criteria

I have a list of names and a list of categories in a table.
Example:
Name Category 1 Category 2 Category 3
Jane Doe X X
Bill Smith X X
Eric Hamilton X
From that list, I want to list the people for each category.
Example:
Category 1 Category 2 Category 3
Jane Doe Jane Doe Bill Smith
Bill Smith Eric Hamilton
Is there a way I can do this in excel?
I found this video which seems to accomplish what I want. The formula is a bit more complicated than what I was hoping for, but it worked. I just removed some of the absolute cell references and copied the formula for the number of categories I currently have and it grouped the users properly.
https://www.youtube.com/watch?v=QkHfZtvC7UQ

Unique numbering of unsorted sets

Is there a way to make this
---A---
John
John
Tim
steve
John
-------
into this:
-----A--------B------
John 1
John 1
Tim 2
Steve 3
John 1
---------------------
Have a large data file with duplicate names, and would like to number them in the way mentioned in order to use them in another way.
Please try:
=IF(COUNTIF(A$1:A2,A2)=1,MAX(B$1:B1)+1,VLOOKUP(A2,A$1:B1,2,0))
in B2 copied down, with labels or blanks in Row1.

Resources