Last active
July 30, 2022 08:27
-
-
Save realhardik18/6d9975e8b21989afadd836c800df8b31 to your computer and use it in GitHub Desktop.
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
from flask import Flask | |
from flask_restful import Resource, Api, reqparse | |
import pandas | |
app = Flask(__name__) | |
api = Api(app) | |
#download the data set from https://www.kaggle.com/datasets/fernandol/countries-of-the-world | |
dataset = pandas.read_csv('countries of the world.csv') | |
def InfoAboutCountry(country): | |
headers = list(dataset.head(0)) | |
country_data = dataset.loc[dataset['Country'] == country+' '].values[0] | |
return dict(zip(headers, country_data)) | |
class CountryAPI(Resource): | |
def get(self): | |
parser = reqparse.RequestParser() | |
parser.add_argument('country', type=str) | |
country = dict(parser.parse_args())['country'] | |
data = InfoAboutCountry(country) | |
return data | |
api.add_resource(CountryAPI, '/data', endpoint='data') | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment