select | select * from airports | airports |
select | select * from airports limit 3 | airports.head(3) |
select | select id from airports where ident=‘KLAX’ | airports[airports.ident=‘KLAX’].id |
select | select distinct type from airport | airports.type.unique() |
where | select * from airports where iso_region=‘US-CA’ and type=‘seaplane_base’ | airports[(airports.iso_region==‘US-CA) & airports.type == ‘seaplane_base’] |
where | select ident, name, municipality from airports where iso_region=‘US-CA’ and type=‘seaplane_base’ | airports[(airports.iso_region==‘US-CA) & airports.type == ‘seaplane_base’)][[‘ident’, ’name’, ‘municipality’] |
order by | select * from airport_freq where airport_ident=‘KLAX’ order by type | airport_freq[airport_freq.airport_ident == ‘KLAX’].sort_values(’type’) |
order by | select * from airport_freq where airport_ident = ‘KLAX’ order by type desc | airport_freq[airport_freq.airport_ident == ‘KLAX’].sort_values(’type’, ascending=False) |
in | select * from airports where type in (‘heliport’, ‘balloonport’) | airports[airports.type.isin([‘heliport’, ‘balloonport’])] |
not in | select * from airports where type not in (‘heliport’, ‘balloonport’) | airports[~airports.type.isin([‘heliport’, ‘balloonport’])] |
group+count | select iso_country, type, count(*) from airports group by iso_country, type order by iso_country, type | airports.groupby([‘iso_country’, ’type’]).size() |
group+count+order | select iso_country, type, count(*) from airports group by iso_country, type order by iso_country, count(*) desc | airports.groupby([‘iso_country’, ’type’]).size().to_frame(‘size’).reset_index().sort_values([‘iso_country’, ‘size’], ascending=[True, False]) |
having | select type, count(*) from airports where iso_country = ‘US’ group by type having count(*) > 1000 order by count(*) desc | irports[airports.iso_country == ‘US’].groupby(’type’).filter(lambda g: len(g) > 1000).groupby(’type’).size().sort_values(ascending=False) |
topN | select iso_country from by_country order by size desc limit 10 | by_country.nlargest(10, columns=‘airport_count’) |
topN+offset | select iso_country from by_country order by size desc limit 10 offset 10 | by_country.nlargest(20, columns=‘airport_count’).tail(10) |
aggregate | select max(length_ft), min(length_ft), avg(length_ft), median(length_ft) from runways | runways.agg({’length_ft’: [‘min’, ‘max’, ‘mean’, ‘median’]}) |
join | select airport_ident, type, description, frequency_mhz from airport_freq join airports on airport_freq.airport_ref = airports.id where airports.ident = ‘KLAX’ | airport_freq.merge(airports[airports.ident == ‘KLAX’][[‘id’]], left_on=‘airport_ref’, right_on=‘id’, how=‘inner’)[[‘airport_ident’, ’type’, ‘description’, ‘frequency_mhz’]] |
union | select name, municipality from airports where ident = ‘KLAX’ union all select name, municipality from airports where ident = ‘KLGB’ | pd.concat([airports[airports.ident == ‘KLAX’][[’name’, ‘municipality’]], airports[airports.ident == ‘KLGB’][[’name’, ‘municipality’]]]) |
insert | create table… insert… | df1 = pd.DataFrame({‘id’: [1, 2], ’name’: [‘Harry Potter’, ‘Ron Weasley’]}) df2 = pd.DataFrame({‘id’: [3], ’name’: [‘Hermione Granger’]}) pd.concat([df1, df2]).reset_index(drop=True) |
update | update airports set home_link = ‘http://www.lawa.org/welcomelax.aspx'where ident == ‘KLAX’ | airports.loc[airports[‘ident’] == ‘KLAX’, ‘home_link’] = ‘http://www.lawa.org/welcomelax.aspx' |
delete | delete from lax_freq where type = ‘MISC’ | lax_freq = lax_freq[lax_freq.type != ‘MISC’] |