Trying to do a xlookup equivalent with pd.merge but not working - pandas-merge

I apologize in advance, this my first time asking a question.
I am trying to match 'City' & 'State' in two different data frames and then bring matching lat & long coordinates. Both data sets have 'City' & 'State' spelled the same and both columns have matching dtypes.
The output as far as the column names is correct, but the row contents are null for lat & long. But for a city like Itacha NY, it definitely is in the zip_codes dataframe with lat & long.
script i've written
df_zips = pd.merge(df, zip_codes,
on = ['City', 'State'],
how = 'left')
df_zips
screenshot of code

Related

Compare two columns and return vallue from substring in google sheets

Basically I'm too dumb to figure out how to update my works sheet.
We've used a spreadsheet to write down all our protocols and they all are linked to an address which along the years each worker has put data in their own way and got messy, so I wanna update it to discard all unnecessary info (like street name, zipcode, etc) and just put the name of the city.
TL:DR
What I wanted to do is: I have a column with full addresses written in so particular standard and a column with the list of cities. I want a formula that will search each city name inside the full address column and return just the name of the city that is written somewhere in the cell.
Edit: Here's a sample of it: https://docs.google.com/spreadsheets/d/1pP1CK2PPiGy2q_3CsCHHnShfa5bfddqRUfKEQWFERiw/edit?usp=sharing
(The column C should find the city name from each cell in column A)
ADDRESS IN Column A, list of cities in Column B:
=ARRAYFORMULA(REGEXEXTRACT(A2:A,TEXTJOIN("|",TRUE,B:B)))

Matching a city and postcode to a list in G Sheets

Apologies in advance if this question is worded poorly. I'm struggling to find the words to define the issue that I am having / would like to resolve.
I would like to know if there is a way that I can match a city and postcode prefix to a list of postcodes that I have so that the result will tell me if the postcode appears on my postcode list for that city?
I have used the following formula =SUMPRODUCT(--(F4='Catchment Area Postcodes'!$A:$BZ))>0, to match an individual postcode to a range of postcodes for an individual city, but this is not dynamic if I wish to look up another city.
I would like to know if there is a way to make this dynamic so that it links to the city that I am searching for?
I'm a newbie here, so I can't upload screenshots yet, unfortunately, but Cell F4 features a postcode Prefix (HU4). To make my formula dynamic, I know that I will need to factor in the city, which I select from a drop-down in cell B7.
The range Catchment Area Postcodes'!$A:$BZ is the full list of cities and postcode prefixes for each. The city names are in column A and the lists of postcodes are in the remaining columns.
Is it possible to add something to my current formula, or is this a dead-end?
Thanks!
use:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A; D2:E; 2; 0)))
I have been trying to lookup a value in a 2 dimensional array with row headings but no column headings.
The following formula has worked for me:
=INDEX('Catchment Area Postcodes'!$B:$BY,SUMPRODUCT(('Catchment Area Postcodes'!$B:$BY=F4)*ROW('Catchment Area Postcodes'!$BY:$BY)),1)

Modify information in Google Sheet Cell based on information in another cell

I need help. I have a spreadsheet that has street addresses with the city compressed behind the street address.
(Example: A1: 123 Flowers StreetRichmond )
I have the city in the adjacent col.
(Example: B1: Richmond )
I need a script that will reference the city name in B1 and give me the street address in Column C without the city.
(Example: C1: 123 Flowers Street )
Can this be done?
One last Challenge. I need it to recognize the city name regardless of case. I have some in ALL CAPS and some in Title Case (Example: RICHMOND or Richmond)
Thanks for any help
Try: =left(A1,search(B1,A1)-1)
Breakdown
search(B1,A1): this searches for the city (B1) in the full address (A1). SEARCH is case-insensitive, so the case of B1 is irrelevant.
Based on the test data of "123 Flowers StreetRichmond", this search returns 19.
=left(A1,search(B1,A1)-1): we know that the city is at the end of the string in A1, so we use "LEFT" to return the characters up to, but excluding the Search value (you have deduct 1 to get only 18 characters).
Based on the test data, the first 18 characters = "123 Flowers Street"

How to run function to split cell data when row added from jotform to google sheet

Firstly thanks for taking the time to look at this, I'm a basic spreadsheet user and what I'd like to achieve here is way over my capability.
I'm using a jotform that collects data on bird sightings (user name, date, species, geolocation), a widget in the form grabs the phone location Latitude & Longitude and concatenates it into one cell (geolocation) with a comma separator eg(56.58542, -5.34016).
When the form is submitted it adds a new row to a google sheet, the sheet has 4x columns [user name] [date] [species] [geolocation].
When a new row is added by the form I'd like to automatically add two extra cells in that row [Latitude] [Longitude] that contain the Lat & Long split into them eg[56.58542] [-5.34016]. I can manually do this with the =SPLIT() function but I'd like to do this automatically as the row is added.
Is this possible and can someone either point me to where I can learn how to do this or post the information here?
Yes it's possible with an ARRAYFORMULA() written in row 1. it would look something like this. Lets say the columns you're looking to populate are L and M. And that your Lat Long is currently in column K. in cell L1, you would write just this one formula. No headers above it, JUST this.
=ARRAYFORMULA({"Lat","Long";IF(K2:K="",,SPLIT(K2:K,", ",0))})
Hope that helps.

How to check if query parameter is empty?

The idea is to generate a list of board games based on parameters like player count, time and/or difficulty level. I am using the QUERY function in Google Sheets.
I have a sheet that has a list of board games. They have separate columns for Title, the minimum number of players, the maximum number of players, difficulty, playtime.
In a second sheet, I have 3 cells which a user can use to write player count (B1), Difficulty (B2) and/or Playtime (B3).
The idea is that with all 3 cells empty, it doesn't show anything, but then you can fill out any or even all of the three cells to filter the complete list of games.
However, if I use one query with all three parameters, if any are empty I get an error.
I've worked around the problem by having multiple nested IFs which check if any of the cells are empty. Based on this, it runs a slightly different QUERY function (i.e., excluding the empty cell). However, this is difficult to troubleshoot and will be a pain to modify if I want to add any additional parameters.
This is the full query:
=QUERY('Lista gier'!A1:H424;"select A,C,D,E,F where C<="&B1&" AND D>="&B1&" AND E='"&B2&"' AND F<="&B12&" AND F>=(0.5*"&B12&") AND B='Gra'");
Expected results are the proper list of games, but I always receive an error:
Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " "C "" at line 1, column 24. Was expecting one of: "(" ... "(" ...
the correct syntax would be:
=QUERY('Lista gier'!A1:H424;
"select A,C,D,E,F
where C <= "&B1&"
and D >= "&B1&"
and E = '"&B2&"'
and F <= "&B12&"
and F >= "&0,5*B12&"
and B = 'Gra'"; 0)
assuming that B1 and B12 are numeric and B2 is a text string

Resources