import numpy as np
import pandas as pd
"""
# Read csv file
"""
df = pd.read_csv('../input/hotel-booking/hotel_booking.csv')
"""
# basis information analysis
"""
df.head()
df.info()
df.shape
"""
### <b>Number of <it>Rows</it></b>:<br>
119390
"""
"""
# non-null counting
"""
nRows = df.shape[0]
ser = df.count()
minimum_non_null_name = ser.idxmin()
minimum_non_null_value = ser.min()
if minimum_non_null_value < nRows:
    print(f'We have missing data\nthe column \'{minimum_non_null_name}\' and it has {nRows - minimum_non_null_value} null values')
"""
# poping 'company'
"""
try:
    company = df.pop('company')
except KeyError:
    print('No company column')
"""
# country based sorting
"""
ser = df.value_counts('country')
ser.sort_values(ascending=False)
ser.head()
"""
# Maximum ADR Payment
"""
idOfMax = df['adr'].idxmax()
name = df.iloc[idOfMax].loc['name']
payment = df.iloc[idOfMax].loc['adr']
print(f'name of The person with max \'adr\':\n {name}\nthe payment is:\n {payment}')
"""
# Mean Of ADRs
"""
meanOfAdr = np.round(df['adr'].mean(), 2)
print(f'Mean of Adrs: {meanOfAdr}')
"""
# Mean Of Stayed Nights
"""
meanOfStayingNights = df['stays_in_week_nights'].mean()
print(f'Mean of Staying Nights: {np.round(meanOfStayingNights,2)}')
"""
# Name and Email of Individuals with Total of Five Special Requests 
"""
totalOfFiveReqs = df[df['total_of_special_requests'] == 5]
totalOfFiveReqs[['name','email']]
"""
# The Five Most Common Names
"""
df.value_counts('name').head()
"""
# Individuals with Maximum Number of Children and Babies
"""
babiesAndChildren = df['babies']+df['children']
babiesAndChildren = babiesAndChildren.sort_values(ascending=False)
df.iloc[babiesAndChildren.index]['name']
"""
# Most Common Region Numbers
"""
def regionCodeExtractor(num):
    regionCode = str(num)[:3]
    return regionCode

regionCodes = df['phone-number'].apply(regionCodeExtractor)
regionCodes.value_counts().head(3)