Convert address into country - python-3.x

I have a panda table which has many countries as location based. The table is shown link this
Real Table |After conversion
Edinburgh, Scotland |UK
Nairobi, Kenya| Kenya
Manchester| UK
uk |UK
Sirajganj |Bangladesh
How to do that in python?
or coordinated to the country?
+05.0738+047.3288 to Somalia
+60.45148+022.26869 to Finland
+51.50853-000.12574 to United Kingdom
+33.24428-086.81638 to USA
+47.55839+007.57327 to Switzerland

This program is solved using Yandex python.
import geocoder
g = geocoder.yandex([55.95, 37.96], method='reverse')
print(g.json)
g.json['country']

Related

How to link the content of two cells

I have an excel file with 2 different sheets. In one i have a list of cities, in the other one i have all the trains that go in that specific city. I have linked the city's name cells with the corresponding in the list. If i add another city and reorganize the list in alphabetic order the trains sheet will have the city's names all changed. How can i connect the content of two different cells so that if i reorganize the list the names in the trains sheet will not change? I looked gor a solution in the official microsoft forum but i didn't find anything
I'm using VLOOKUP() function and it works
In CITIES-STATIONS.xlsx file I'm taking 3 columns as array I'm
getting the column 3 to show in Trains.xlsx file
I added Florida City and is taking the value of the station the formula is in the Trains.xlsx file:
=VLOOKUP(B2,'[1-CITIES-STATIONS.xlsx]Stations'!$A$1:$C$44,3,FALSE)
=VLOOKUP(Searching Value, Array ,Column to get in to the Trains File, Bolean Value in case null)
1-CITIES-STATIONS.xls file
A B C
City State Station Name
Alpine TX (ALP)
Alton IL (ALN)
Arkadelphia AR (ARK)
Austin TX (AUS)
Benson AZ (BEN)
Bloomington IL Uptown Station (BNL)
Carlinville IL (CRV)
Chicago IL Union Station (CHI)
Cleburne TX (CBR)
Dallas TX Union Station (DAL)
Del Rio TX (DRT)
Deming NM (DEM)
El Paso TX Union Depot (ELP)
Florida MI Amtrak Florida <------
Fort Worth TX (FTW)
Hope AR (HOP)
2-TRAINS.xls file
A B C
Train Company City Station
Amtrak. Malvern (MVN) <---formula here
Amtrak. Arkadelphia (ARK)
Amtrak. Palm Springs Amtrak Station (PSN)
Amtrak. Florida Amtrak Florida <------
Norfolk Southern Railway. Hope (HOP)
Norfolk Southern Railway. Texarkana (TXA)
Norfolk Southern Railway. Marshall (MHL)
Norfolk Southern Railway. Longview (LVW)
Norfolk Southern Railway. Mineola (MIN)
Union Pacific Railroad. Dallas U.S. (DAL)
Union Pacific Railroad. Fort Worth (FTW)
Union Pacific Railroad. Cleburne (CBR)
Union Pacific Railroad. McGregor (MCG)
Union Pacific Railroad. Temple (TPL)
Union Pacific Railroad. Taylor (TAY)
BNSF Railway. Austin (AUS)
Good luck!

Excel formula for aggregation and filtering

Is it possible to aggregate values on one excel tab and display on another tab?
In addition to that can we also filter on one of the columns as we aggregate?
For example, Sheet1 has 3 columns - (Continent, City, Ignore)
Continent City Ignore
Europe Paris N
Europe London N
Europe Liverpool N
Europe Rome N
Europe Oslo Y
Asia Tokyo N
Asia Osaka N
Asia Dubai N
Asia Bangkok Y
Asia Mumbai N
Africa Cairo Y
I want my Sheet2 to display the number of cities per continent taking into account the "Ignore" flag.
Continent #Cities
Europe 4
Asia 4
Africa 0
Since 3 Cities are marked as Ignore=Y, we don't want to count them.
It came as one of the recommended pivot tables, but I'm trying to build this using excel formulas so I can build on that if needed.
Prefer excel formulas over VBA or Macro.
Using your sample data...
Formula in F2:
=COUNTIFS($A$2:$A$12,E2,$C$2:$C$12,"N")
Drag down...

converting comma separated data of excel file into new line using python, pandas

I have an excel file with data as
StudentId Details
1234 John, Texas, United States
9887 Roma, Moscow, Russia
I want to convert it into the following format, such that:
StudentId Details
1234 John
Texas
United States
9887 Roma
Moscow
Russia
I am using Pandas for this purpose but not getting the results
for i in range(len(df['Details'])):
df['Details'][i]=df['Details'][i].replace(',','\n')
I am using somewhat this kind of logic
Read it in with read_fwf() then split up that column later:
df['Details'].str.split(',')

Extracting Data from a line

I have some data that looks like this (This is real countries but no sensitive data) It is formatted exactly like i posted
Calgary, Alberta T2P 0B3 Canada
Thunder Bay, Ontario P7G 0A1 Canada
Toronto, Ontario M3A 1E5 Canada
Calgary, Alberta T2G 1C6 Canada
Calgary, Alberta T2N 1C2 Canada
Edmonton, Alberta T5J 2W8 Canada
New Westminster, British Columbia V3L 5T4 Canada
London, Ontario N6A 5P6 Canada
Guelph, Ontario N1G 2W1 Canada
Whitby, Ontario L1N 4Z1 Canada
Red Deer, Alberta T4R 0L4 Canada
Edmonton, Alberta T5H 0S2 Canada
West Kelowna, British Columbia V4T 3E3 Canada
I am trying to get the Canadian zip code (N6A 5P6, N1G 2W1, etc) in 1 cell (so 1 cell per line with the zipcode.
So it will look like
Original data, zip code
original data, zip code
I figured out how to do it for american zip codes, but that space is messing me up. Thank you.
I think this should work, assuming it always ends with Canada:
=MID(A1,SEARCH("Canada",A1)-8,8)
You could split the content on spaces and just drop the final content of the split (which will always be Canada), preserving the elements at index -2 and -3 (the zip elements)

Spreadsheet : every possible combination of 2 columns into one single colum

and sorry if this question looks familiar, I saw a lot of similar problems but couldn't understand the trick, and I completely stuck.
I have a spreadsheet with 2 columns :
A with Countries
B with their code
A B
Belgium BE
England EN
France FR
Luxembourg LX
Netherlands NL
Spain SP
I'm trying to generate generate a matrix representing all the possible travels : Travel from A to A, from A to B, from B to A, and from B to B. The only restriction is not to travel from a country to itself.
At the end I want to generate the result in a single column C, like this :
Travel from Belgium to England Travel from Belgium to France
Travel from Belgium to Luxembourg Travel from Belgium to
Netherlands Travel from Belgium to Italy Travel from Belgium
to Spain Travel from England to Belgium Travel from England to
France Travel from England to Luxembourg Travel from England
to Netherlands Travel from England to Italy Travel from
England to Spain etc Travel from Belgium to EN Travel from
Belgium to FR Travel from Belgium to LX Travel from Belgium to
NL etc Travel from BE to EN Travel from BE to FR
Travel from BE to LX etc Travel from BE to England Travel
from BE to France etc
Can anyone help me with that ? I tried several tricks with concatenation and JOIN, but I don't get anywhere ...
Thanks a lot in advance
You can run through each value in column A and associate it with a staggered value from column B but you will have to perform some mathematical trickery using the INT function and MOD function to have the sixth entry in column A associated with the first entry in column B.
        
The formulas in C2:E2 are,
=INDEX(A$2:A$7, INT((ROW(1:1)-1)/(COUNTA(A$2:A$7)-1))+1)
=INDEX(B$2:B$7, MOD(MOD((ROW(1:1)-1), (COUNTA(B$2:B$7)-1))+INT((ROW(1:1)-1)/(COUNTA(B$2:B$7)-1))+1, COUNTA(A$2:A$7))+1)
="Travel from "&C2&" to "&D2
There may be a more elegant way of looping through the destinations while skipping the origin but this works and it is not calculation intensive despite the apparent complexity of the formula(s).
I've used the COUNTA function to determine the number of entries rather than hard-code in ordinal numbers. You should be able to transcribe this for more or less entries by following and modifying the referenced cell ranges.

Resources