This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat verylongfile.txt | more # shows the content of verylongfile.txt split in pages | |
cat verylongfile.txt | less # shows the content of verylongfile.txt split in pages, with support for scrolling and backwards navigation | |
cat verylongfile.txt | grep "I love you" # shows the lines where the string "I love you" is found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
help nano # brief summary about the command "nano" | |
man nano # detailed info about the command "nano" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate the average percentage of restaurants of each cuisine for the 9 analyzed cities | |
famous_cuisines = cuisines_city_normalized.mean(axis=0) | |
# Get the top 10 cuisines around the world | |
famous_cuisines = famous_cuisines.sort_values(ascending=True) | |
famous_cuisines = famous_cuisines.tail(10) | |
# Plot the data in a horizontal bar graph | |
famous_cuisines.plot(kind='barh') | |
plt.xlabel('Average % of restaurants in the cities') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
percentages = {} | |
for city, cuisine in city_local_cuisines.items(): | |
# For each city, get the percentage of local cuisine restaurants | |
percentage = cuisines_city_normalized.at[city, cuisine] | |
percentages[city] = percentage | |
# Plot the data in a bar graph | |
df_percentages = pd.Series(percentages).sort_values(ascending=True) | |
df_percentages.plot(kind='barh') | |
plt.xlabel('% of local cuisine restaurants') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig = plt.figure() | |
for index, cuisine in enumerate(city_local_cuisines.values()): | |
# For the selected cuisine, plot a bar graph with the cities where there are more restaurants of that cuisine | |
ax = fig.add_subplot(3, 3, index+1) | |
cuisine_cities = cuisines_city_normalized[cuisine] | |
cuisine_cities = cuisine_cities.sort_values(ascending=True).head(9) | |
# Plot in red the bar with the city where this cuisine is local, plot in blue the rest | |
color = '' | |
for i in cuisine_cities.keys(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig = plt.figure() | |
for index, city in enumerate(cities): | |
# For each city, get the top 10 cuisines and plot them in a horizontal bar graph | |
ax = fig.add_subplot(3, 3, index+1) | |
# Get the top 10 cuisines for the city | |
cuisines = cuisines_city_normalized.loc[city] | |
cuisines = cuisines.sort_values(ascending=False).head(10).sort_values(ascending=True) | |
# Plot in red the bar with the local cuisine, plot in blue the rest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# One-hot encoding | |
restaurants_onehot = pd.get_dummies(restaurants['Cuisine'], prefix="", prefix_sep="") | |
restaurants_onehot = restaurants_onehot.multiply(restaurants['Number of restaurants'], axis=0) | |
restaurants_onehot = pd.concat([restaurants['City'], restaurants_onehot], axis=1) | |
# Group by city | |
cuisines_city = restaurants_onehot.groupby('City').sum().reset_index() | |
cuisines_city = cuisines_city.set_index(keys='City') | |
# Normalize the numbers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
restaurants = pd.DataFrame(columns=['City', 'Cuisine', 'Number of restaurants']) # define the DataFrame where the results will be stored | |
for city in cities: | |
for cuisine_name, category_id in cuisines.items(): | |
# For each city, retrieve the top restaurants from Foursquare for each cuisine... | |
query = requests.get("{url}&near={city}&categoryId={category_id}".format(url=URL, city=city, category_id=category_id)) | |
if query.status_code == 200: | |
number = query.json() | |
restaurants = restaurants.append({ | |
'City': city, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define the dependencies | |
import pandas as pd | |
import requests | |
import matplotlib as mpl | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
mpl.style.use(['seaborn']) | |
# Foursquare API credentials and endpoint | |
CLIENT_ID = # your client ID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.8" | |
services: | |
database: | |
image: mysql:latest | |
volumes: | |
- db-data:/var/lib/mysql/data | |
command: --default-authentication-plugin=mysql_native_password # run this command in the container | |
networks: | |
- database-api | |
restart: always # the container must be always on |