<jupyter_start><jupyter_text>Pandas and Matplotlib Exercises 1 1. Import GlobalLandTemperaturesByMajorCity.csv from data<jupyter_code>import pandas as pd
glt_mc = pd.read_csv('data/GlobalLandTemperaturesByMajorCity.csv')<jupyter_output><empty_output><jupyter_text>2. Look at the first 5 entries<jupyter_code>glt_mc.head()<jupyter_output><empty_output><jupyter_text>3. Print the name of all the columns<jupyter_code>glt_mc.columns<jupyter_output><empty_output><jupyter_text>4. What is the number of observations (rows) in the dataset?<jupyter_code>print(glt_mc.shape) #will give you both (observations/rows, columns)
print(glt_mc.shape[0]) #will give you only the columns number<jupyter_output><empty_output><jupyter_text>5. Which temporal range  is covered by this dataset?<jupyter_code>glt_mc['dt'] = pd.to_datetime(glt_mc['dt'])
glt_mc = glt_mc.set_index('dt')
glt_mc.index.min()
glt_mc.index.max()<jupyter_output><empty_output><jupyter_text>6. Count the number of cities in the dataset<jupyter_code>n_cities = len(pd.unique(glt_mc['City']))
n_cities<jupyter_output><empty_output><jupyter_text>7. Extract the average temperature for Moscow, London, Madrid, Berlin and Lisboa<jupyter_code>temp_cities = glt_mc[(glt_mc['City'] == 'London') | (glt_mc['City'] == 'Moscow') | (glt_mc['City'] == 'Madrid') | (glt_mc['City'] == 'Berlin') | (glt_mc['City'] == 'Lisboa') ]
temp_cities<jupyter_output><empty_output><jupyter_text>8. Create a boxplot comparing the average temperature of Moscow, London, Madrid, Berlin and Lisboa<jupyter_code>import matplotlib.pyplot as plt
import seaborn as sns

sns.set(style="darkgrid")

plt.figure(figsize=(16, 10))
plt.xticks(rotation=90)

sns.boxplot(x='City', y="AverageTemperature", data=temp_cities, palette="coolwarm")<jupyter_output><empty_output><jupyter_text>9. Plot the distribution of average temperatures in Berlin<jupyter_code>plt.title("Distribution of AverageTemperature")
plt.hist(temp_cities['AverageTemperature']);<jupyter_output><empty_output><jupyter_text>10. What was the hottest year in Berlin during the observation period?<jupyter_code>temp_berlin = temp_cities[temp_cities['City'] == 'Berlin']
temp_berlin.index[temp_berlin['AverageTemperature'] == temp_berlin['AverageTemperature'].max()]<jupyter_output><empty_output><jupyter_text>11. Plot a heatmap showing the average monthly temperature of Berlin between 2000 and 2013 [X-Axis = Year, Y-Axis = Month ]<jupyter_code>temp_b_2000 = temp_berlin[temp_berlin.index >= '2000-01-01']
temp_b_2000['Month'] = temp_b_2000.index.month.values
temp_b_2000['Year'] = temp_b_2000.index.year.values
data = temp_b_2000.pivot(index='Month', columns='Year',values="AverageTemperature")
plt.figure(figsize=(15,15))
plt.title("Monthly Temprature from year 2000 to 2013")
sns.heatmap(data,annot=True, cmap='Reds');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13290915517850832, 'fraction_numerical': 0.026157652880876636, 'mean_word_length': 9.481481481481481, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '89817', 'license': 'MIT', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1027, 'n_words': 190, 'path': '1_Basic_Python/exercises/solutions/02_Pandas_Matplotlib_Exercise_1_solutions.ipynb', 'repo_name': 'eo2cube/datacube_eagles', 'size': '2829'}