How can I find whether a city in US belongs to east or west coast by using its latitude and longitude?
I have the lat and long for the city in US but could not find if it belongs to east or west
Here's a map showing latitudes. Decide where you want to cutover.
https://www.worldatlas.com/webimage/countrys/usalats.htm
Maybe > 115 could be west coast, < 95 east coast?
Related
I have some accounting data where I need to select a single row within a group if it meets a dollar amount criteria OR if it does not I need to sum/combine multiple rows in that group to see if that group meets the criteria. Example data:
Continent
Region
Sales Amount
South America
North
$300
South America
South
$100
South America
West
$500
South America
East
$200
North America
North
$100
North America
South
$50
North America
West
$50
North America
East
$400
Europe
North
$100
Europe
South
$200
Europe
West
$100
Europe
East
$100
Asia
North
$75
Asia
South
$100
Asia
West
$100
Asia
East
$100
Africa
North
$500
Africa
South
$700
Africa
West
$100
Africa
East
$100
In the above example, I want to find all continents that have single regions/rows with $500 in sales OR I want to find countries where 2 or more regions can be combined to meet the $500 amount. My expected result would be:
Continent
Region_1
Region_2
Sales Amount_1
Sales Amount_2
Canada
West
not applicable
$500
USA
North,East
not applicable
$500
Europe
North,South,West,East
not applicable
$500
Asia
does not meet criteria
not applicable
does not meet criteria
Africa
South
North
$700
$500
Region_2 is only applicable if more than one region within a continent meets the sales amount criteria of $500 on its own.
I am busy messing around in SQLite and want to calculate the Gini coefficient per US states based on median income per capita and the populations per county.
The process is explained here: https://medium.com/google-cloud/calculating-gini-coefficient-in-bigquery-3bc162c82168
Only I have no idea how to do this for my particular data set. I understand that I would need to determine the % of income and population per county and then aggregate that per state to get the cumulative values, but other than that I am completely lost.
The output would then be the Gini coefficient per state but dont know how I could create a new entity with these values.
A sample of my data set is as follows, and although not complete, there should be enough data to get it working.
State
County
TotalPop
IncomePerCap
Alabama
Autauga
55221
24974
Alabama
Baldwin
195121
27317
Alabama
Barbour
26932
16824
Alabama
Bibb
22604
18431
Alabama
Blount
57710
20532
Alabama
Bullock
10678
17580
Alabama
Butler
20354
18390
Alabama
Calhoun
116648
21374
Alabama
Chambers
34079
21071
Alabama
Cherokee
26008
21811
Alaska
Bristol Bay Borough
970
38267
Alaska
Denali Borough
2060
35315
Alaska
Dillingham Census Area
4979
22257
Alaska
Fairbanks North Star Borough
99705
33244
Alaska
Haines Borough
2560
33902
Alaska
Hoonah-Angoon Census Area
2128
30943
Alaska
Juneau City and Borough
32531
39979
Alaska
Kenai Peninsula Borough
57221
31537
Alaska
Ketchikan Gateway Borough
13699
32021
Alaska
Kodiak Island Borough
13973
30657
I am trying to understand how the range pattern matching work in Awk
Here is the full data that I am practicing with
Raw Data
-----------------------------------------
USSR 8649 275 Asia
Canada 3852 25 North America
China 3705 1032 Asia
USA 3615 237 North America
Brazil 3286 134 South America
India 1267 746 Asia
Mexico 762 78 North America
France 211 55 Europe
Japan 144 120 Asia
Germany 96 61 Europe
England 94 56 Europe
If I write this code
$ awk '/Asia/, /Europe/' countries.awk
I get
USSR 8649 275 Asia
Canada 3852 25 North America
China 3705 1032 Asia
USA 3615 237 North America
Brazil 3286 134 South America
India 1267 746 Asia
Mexico 762 78 North America
France 211 55 Europe
Japan 144 120 Asia
Germany 96 61 Europe
It doesn't output England.
And If I write this
$ awk '/Europe/, /Asia/' countries.awk
I get
France 211 55 Europe
Japan 144 120 Asia
Germany 96 61 Europe
England 94 56 Europe
What is the behavior here? Why do I not get England on the first one?
Awk process input lines one at a time, the syntax you used is likely to print lines from the start to the end pattern, represented by country names. When you used
awk '/Asia/, /Europe/'
The start of pattern Asia happens more than once. As you can see from the line numbers below, numbers 3,5,8 and 11 represent the start of the pattern and the pattern ends at lines 10 and 12. Observe carefully the sub-ranges of lines between 8-10 and 11-12. The last end pattern Europe for the last Asia ends at line 12, that is the reason you are not seeing England in the first case.
But when you used
awk '/Europe/, /Asia/'
The line containing the first start pattern Europe starts at line 10 and ends at 11 another two pattern start at 12 and 13 without an end pattern Asia, so it would obviously print all the lines until Asia appears. So you are seeing England in the second case.
$ cat -n file
1 Raw Data
2 -----------------------------------------
3 USSR 8649 275 Asia
4 Canada 3852 25 North America
5 China 3705 1032 Asia
6 USA 3615 237 North America
7 Brazil 3286 134 South America
8 India 1267 746 Asia
9 Mexico 762 78 North America
10 France 211 55 Europe
11 Japan 144 120 Asia
12 Germany 96 61 Europe
13 England 94 56 Europe
Never use range expressions as they make trivial tasks very slightly briefer but then need a complete rewrite or duplicate conditions when your requirements change. Always use a flag instead:
awk '/Asia/{f=1} f{print} /Europe/{f=0}' countries.awk
I bet if you started with that you wouldn't even have had to ask this question as the logic is clear and explicit.
Can anyone help me with preparing data for the new feature Geo Maps. I want to show the below data on geo maps.
Country Name Sales
Russia 1244
Canada 3553
Germany 5345
Australia 2456
France 2566
United Kingdom 6743
India 3677
United States 5633
Thanks in advance,
the setup is quite easy and you can find out more information here:
https://developer.gooddata.com/article/setting-up-data-for-geo-charts
Basically it is about setting up the correct date type for columns that represents geo-information.
JT
i read the book "Sams Teach Yourself SQL in 10 minutes, Third Edition" and in the lesson 10 "Grouping Data", section "Creating Groups", i can't understand the following:
"Aside from the aggregate calculations statements, every column in your SELECT statement must be present in the GROUP BY clause."
Why? I tried this and i think that it is not true.
For example, consider a table 'World' with the columns 'continent', 'country', 'population'.
SELECT continent, country
FROM World
GROUP BY continent;
According to the book, this should lead to an error, right? But it doesn't. I can group my data depending on the continent (so we have at the results 7 continents) and next to each continent, a random country name.
Like this
continent country
North America Canada
South America Brazil
Europe France
Africa Cameroon
Asia Japan
Australia New Zealand
Antarctica TuxLand
You are most probably using MySQL which allows ungrouped and unaggregated expressions in SELECT clause.
This is violation of standard of course.
This is intended to simplify GROUP BY with joins on a PRIMARY KEY:
SELECT a.*, SUM(b.value)
FROM a
JOIN b
ON b.a_id = a.id
GROUP BY
a.id
Normally, you would have either to add all columns from a into the GROUP BY clause or use a subquery.
MySQL allows you not to do it since all values from a are guaranteed to be the same for a given value of the PRIMARY KEY (which is grouped on).
This is correct and should produce no error in some forms of SQL such as MySQL. You may optionally use the GROUP BY statement on more than one column but it's not required.
GROUP BY will list the first result of the columns specified - so in your case, it would return the first country/continent pair.
PostgreSQL and MySQL allow this, using one field for the group by.
The tutorial probably assumes you should use GROUP BY on all fields so from what you select, you don't lose any data - it would show every country/continent in the above example, but only once.
Here's an example table:
Continent | Country | Random_Field
---------------------------------------------
North America Canada Cake
North America Canada Dog
South America Brazil Cat
Europe France Frog
Africa Cameroon House
Asia Japan Gadget
Asia India Dance
Australia New Zealand Frodo
Antarctica TuxLand Linux
In your first statement:
SELECT continent, country
FROM World
GROUP BY continent;
The output would be:
Continent | Country
--------------------------
North America Canada
South America Brazil
Europe France
Africa Cameroon
Asia Japan
Australia New Zealand
Antarctica TuxLand
Notice one of the Asia rows was lost, despite being different.
Using a GROUP BY on both:
SELECT continent, country
FROM World
GROUP BY continent, country;
Would yield:
Continent | Country
-----------------------------
North America Canada
South America Brazil
Europe France
Africa Cameroon
Asia Japan
Asia India
Australia New Zealand
Antarctica TuxLand