Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
276 changes: 276 additions & 0 deletions .ipynb_checkpoints/Solution-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"Places\" : [ {\n",
" \"PlaceId\" : \"STOC-sky\",\n",
" \"PlaceName\" : \"Stockholm\",\n",
" \"CountryId\" : \"SE-sky\",\n",
" \"RegionId\" : \"\",\n",
" \"CityId\" : \"STOC-sky\",\n",
" \"CountryName\" : \"Sweden\"\n",
" }, {\n",
" \"PlaceId\" : \"ARN-sky\",\n",
" \"PlaceName\" : \"Stockholm Arlanda\",\n",
" \"CountryId\" : \"SE-sky\",\n",
" \"RegionId\" : \"\",\n",
" \"CityId\" : \"STOC-sky\",\n",
" \"CountryName\" : \"Sweden\"\n",
" }, {\n",
" \"PlaceId\" : \"NYO-sky\",\n",
" \"PlaceName\" : \"Stockholm Skavsta\",\n",
" \"CountryId\" : \"SE-sky\",\n",
" \"RegionId\" : \"\",\n",
" \"CityId\" : \"STOC-sky\",\n",
" \"CountryName\" : \"Sweden\"\n",
" }, {\n",
" \"PlaceId\" : \"BMA-sky\",\n",
" \"PlaceName\" : \"Stockholm Bromma\",\n",
" \"CountryId\" : \"SE-sky\",\n",
" \"RegionId\" : \"\",\n",
" \"CityId\" : \"STOC-sky\",\n",
" \"CountryName\" : \"Sweden\"\n",
" }, {\n",
" \"PlaceId\" : \"VST-sky\",\n",
" \"PlaceName\" : \"Stockholm Vasteras\",\n",
" \"CountryId\" : \"SE-sky\",\n",
" \"RegionId\" : \"\",\n",
" \"CityId\" : \"STOC-sky\",\n",
" \"CountryName\" : \"Sweden\"\n",
" } ]\n",
"}\n"
]
}
],
"source": [
"import requests\n",
"\n",
"url = \"https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/autosuggest/v1.0/UK/GBP/en-GB/\"\n",
"\n",
"querystring = {\"query\":\"Stockholm\"}\n",
"\n",
"headers = {\n",
" 'x-rapidapi-host': \"skyscanner-skyscanner-flight-search-v1.p.rapidapi.com\",\n",
" 'x-rapidapi-key': \"9c8d07c07emsh4f918e8fccf6096p166317jsna5619b1b6eec\"\n",
" }\n",
"\n",
"response = requests.request(\"GET\", url, headers=headers, params=querystring)\n",
"\n",
"print(response.text)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"Quotes\" : [ {\n",
" \"QuoteId\" : 1,\n",
" \"MinPrice\" : 68,\n",
" \"Direct\" : true,\n",
" \"OutboundLeg\" : {\n",
" \"CarrierIds\" : [ 851 ],\n",
" \"OriginId\" : 81727,\n",
" \"DestinationId\" : 60987,\n",
" \"DepartureDate\" : \"2021-11-11T00:00:00\"\n",
" },\n",
" \"QuoteDateTime\" : \"2021-10-11T10:15:00\"\n",
" } ],\n",
" \"Carriers\" : [ {\n",
" \"CarrierId\" : 851,\n",
" \"Name\" : \"Alaska Airlines\"\n",
" } ],\n",
" \"Places\" : [ {\n",
" \"Name\" : \"New York John F. Kennedy\",\n",
" \"Type\" : \"Station\",\n",
" \"PlaceId\" : 60987,\n",
" \"IataCode\" : \"JFK\",\n",
" \"SkyscannerCode\" : \"JFK\",\n",
" \"CityName\" : \"New York\",\n",
" \"CityId\" : \"NYCA\",\n",
" \"CountryName\" : \"United States\"\n",
" }, {\n",
" \"Name\" : \"San Francisco International\",\n",
" \"Type\" : \"Station\",\n",
" \"PlaceId\" : 81727,\n",
" \"IataCode\" : \"SFO\",\n",
" \"SkyscannerCode\" : \"SFO\",\n",
" \"CityName\" : \"San Francisco\",\n",
" \"CityId\" : \"SFOA\",\n",
" \"CountryName\" : \"United States\"\n",
" } ],\n",
" \"Currencies\" : [ {\n",
" \"Code\" : \"USD\",\n",
" \"Symbol\" : \"$\",\n",
" \"ThousandsSeparator\" : \",\",\n",
" \"DecimalSeparator\" : \".\",\n",
" \"SymbolOnLeft\" : true,\n",
" \"SpaceBetweenAmountAndSymbol\" : false,\n",
" \"RoundingCoefficient\" : 0,\n",
" \"DecimalDigits\" : 2\n",
" } ]\n",
"}\n"
]
}
],
"source": [
"\n",
"url = \"https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/browsequotes/v1.0/US/USD/en-US/SFO-sky/JFK-sky/2021-11-11\"\n",
"\n",
"querystring = {\"inboundpartialdate\":\"2021-11-11\"}\n",
"\n",
"headers = {\n",
" 'x-rapidapi-host': \"skyscanner-skyscanner-flight-search-v1.p.rapidapi.com\",\n",
" 'x-rapidapi-key': \"9c8d07c07emsh4f918e8fccf6096p166317jsna5619b1b6eec\"\n",
" }\n",
"\n",
"response = requests.request(\"GET\", url, headers=headers, params=querystring)\n",
"\n",
"print(response.text)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame(response.json().items())"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>new_col</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Quotes</td>\n",
" <td>[{'QuoteId': 1, 'MinPrice': 68, 'Direct': True...</td>\n",
" <td>{'QuoteId': 1, 'MinPrice': 68, 'Direct': True,...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Carriers</td>\n",
" <td>[{'CarrierId': 851, 'Name': 'Alaska Airlines'}]</td>\n",
" <td>{'CarrierId': 851, 'Name': 'Alaska Airlines'}</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Places</td>\n",
" <td>[{'Name': 'New York John F. Kennedy', 'Type': ...</td>\n",
" <td>{'Name': 'New York John F. Kennedy', 'Type': '...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Currencies</td>\n",
" <td>[{'Code': 'USD', 'Symbol': '$', 'ThousandsSepa...</td>\n",
" <td>{'Code': 'USD', 'Symbol': '$', 'ThousandsSepar...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 \\\n",
"0 Quotes [{'QuoteId': 1, 'MinPrice': 68, 'Direct': True... \n",
"1 Carriers [{'CarrierId': 851, 'Name': 'Alaska Airlines'}] \n",
"2 Places [{'Name': 'New York John F. Kennedy', 'Type': ... \n",
"3 Currencies [{'Code': 'USD', 'Symbol': '$', 'ThousandsSepa... \n",
"\n",
" new_col \n",
"0 {'QuoteId': 1, 'MinPrice': 68, 'Direct': True,... \n",
"1 {'CarrierId': 851, 'Name': 'Alaska Airlines'} \n",
"2 {'Name': 'New York John F. Kennedy', 'Type': '... \n",
"3 {'Code': 'USD', 'Symbol': '$', 'ThousandsSepar... "
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['new_col'] = df[1].apply(lambda x: x[0])\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading