Coder Social home page Coder Social logo

-presentation-based-on-the-outcomes-of-all-tasks-in-previous-modules-and-labs's Introduction

-presentation-based-on-the-outcomes-of-all-tasks-in-previous-modules-and-labs

Requests allows us to make HTTP requests which we will use to get data from an API

import requests

Pandas is a software library written for the Python programming language for data manipulation and analysis.

import pandas as pd

NumPy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays

import numpy as np

Datetime is a library that allows us to represent dates

import datetime

Setting this option will print all collumns of a dataframe

pd.set_option('display.max_columns', None)

Setting this option will print all of the data in a feature

pd.set_option('display.max_colwidth', None)

Takes the dataset and uses the rocket column to call the API and append the data to the list

def getBoosterVersion(data): for x in data['rocket']: response = requests.get("https://api.spacexdata.com/v4/rockets/"+str(x)).json() BoosterVersion.append(response['name']) # Takes the dataset and uses the payloads column to call the API and append the data to the lists def getPayloadData(data): for load in data['payloads']: response = requests.get("https://api.spacexdata.com/v4/payloads/"+load).json() PayloadMass.append(response['mass_kg']) Orbit.append(response['orbit'])

Takes the dataset and uses the cores column to call the API and append the data to the lists

def getCoreData(data): for core in data['cores']: if core['core'] != None: response = requests.get("https://api.spacexdata.com/v4/cores/"+core['core']).json() Block.append(response['block']) ReusedCount.append(response['reuse_count']) Serial.append(response['serial']) else: Block.append(None) ReusedCount.append(None) Serial.append(None) Outcome.append(str(core['landing_success'])+' '+str(core['landing_type'])) Flights.append(core['flight']) GridFins.append(core['gridfins']) Reused.append(core['reused']) Legs.append(core['legs']) LandingPad.append(core['landpad'])

spacex_url="https://api.spacexdata.com/v4/launches/past" response = requests.get(spacex_url) print(response.content) static_json_url='https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBM-DS0321EN-SkillsNetwork/datasets/API_call_spacex_api.json' response.status_code

Lets take a subset of our dataframe keeping only the features we want and the flight number, and date_utc.

data = data[['rocket', 'payloads', 'launchpad', 'cores', 'flight_number', 'date_utc']]

We will remove rows with multiple cores because those are falcon rockets with 2 extra rocket boosters and rows that have multiple payloads in a single rocket.

data = data[data['cores'].map(len)==1] data = data[data['payloads'].map(len)==1]

Since payloads and cores are lists of size 1 we will also extract the single value in the list and replace the feature.

data['cores'] = data['cores'].map(lambda x : x[0]) data['payloads'] = data['payloads'].map(lambda x : x[0])

We also want to convert the date_utc to a datetime datatype and then extracting the date leaving the time

data['date'] = pd.to_datetime(data['date_utc']).dt.date

Using the date we will restrict the dates of the launches

data = data[data['date'] <= datetime.date(2020, 11, 13)] #Global variables BoosterVersion = [] PayloadMass = [] Orbit = [] LaunchSite = [] Outcome = [] Flights = [] GridFins = [] Reused = [] Legs = [] LandingPad = [] Block = [] ReusedCount = [] Serial = [] Longitude = [] Latitude = [] data_falcon9.loc[:,'FlightNumber'] = list(range(1, data_falcon9.shape[0]+1)) data_falcon9 data_falcon9.isnull().sum() data_falcon9.to_csv('dataset_part_1.csv', index=False)

-presentation-based-on-the-outcomes-of-all-tasks-in-previous-modules-and-labs's People

Contributors

luuuuuuunaaaa avatar

Watchers

 avatar

Forkers

ruchadhage

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.