import pandas as pd
pd.__version__
# Download a sample file from http://insideairbnb.com/
! wget http://data.insideairbnb.com/united-states/fl/broward-county/2022-06-17/visualisations/listings.csv -O listings.csv
# read the airbnb NYC listings csv file
airbnb = pd.read_csv("listings.csv")
# display the pandas DataFrame
display(airbnb)
# View first few entries
airbnb.head()
# View last few entries
airbnb.tail()
# Results for a single column
airbnb['name']
# results for multiple columns
hosts= airbnb[['host_id', 'host_name']]
hosts.head()
# Show the data types for each column
airbnb.dtypes
# Change the type of a column to datetime
airbnb['last_review']=pd.to_datetime(airbnb['last_review'])
airbnb.dtypes
# extract the year from a datetime series
airbnb['year']=airbnb['last_review'].dt.year
airbnb['year'].head()
# strip leading and trailing spaces from a string series
airbnb['name']= airbnb['name'].str.strip()
airbnb['name'].head()
# uppercase all strings in a series
airbnb['name_upper']= airbnb['name'].str.upper()
airbnb['name_upper'].head()
#lowecase all strings
airbnb['name_lower']= airbnb['name'].str.lower()
airbnb['name_lower'].tail()
# calculate using two columns
airbnb['min_revenue'] = airbnb['minimum_nights'] * airbnb['price']
airbnb[['minimum_nights', 'price', 'min_revenue']].head()