Web scraping
import requests
r = requests.get('http://blue.math.buffalo.edu')
r
r.text
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299"
user_agent = {'User-agent': ua}
r = requests.get('http://blue.math.buffalo.edu',headers=user_agent)
import pandas
df = pandas.read_csv('airports.csv')
df.head()
def foo(x):
return x
myconverters = {'continent':foo}
df = pandas.read_csv('airports.csv',converters=myconverters)
df.head(2)
df['type']
df[['latitude_deg','longitude_deg']]
len(df)
import matplotlib.pyplot as plt
%matplotlib inline
plt.figure(figsize=(12,8))
plt.plot(df['longitude_deg'],df['latitude_deg'],'bo',alpha=0.05,ms=2)
plt.savefig('airports.png')
df['latitude_deg'].max()
imax = df['latitude_deg'].argmax()
imax
df.iloc[imax]
df['type'].value_counts()
df[['latitude_deg','longitude_deg']].to_csv('temp.csv',index=False,sep='\t')
df[['latitude_deg','longitude_deg']].to_excel('temp.xlsx')
?pandas.read_csv