df


"""
Explanation: 1. Open your dataset up using pandas in a Jupyter notebook
End of explanation
"""


df.columns

"""
Explanation: 3. Do a .columns to get a feel for your data
End of explanation
"""


df.head()

"""
Explanation: 4. Do a .head() to get a feel for your data
End of explanation
"""


df['Agency'].value_counts()

print("NASA runs a total of 397 lab facilities, Nasa Intelsat runs 17, Department of Defence(DOD) runs 7 labs, Department of Energy runs 12 labs, Raytheon runs 5, and Orbital Sciences Corporation (osc) runs only one NASA lab facility")

"""
Explanation: 4. Write down 12 questions to ask your data, or 12 things to hunt for in the data

Find all the agencies that house a NASA Lab facility.
Count the number of each agencies that house a Nasa Lab facility.
Find the different centers that run a NASA lab, and their count.
List the status of the lab facilities and their count?
Find how many active labs are operating today.
Which of the US states has the highest number of NASA Lab facilities ?
Of all the states that has a NASA lab, which state has the lowest number in the country ?
Group them by agencies.
Group them by centers, and discover how many active labs are operating under each of them.
Find all the cities with a Lab facility. Group them and find how many active labs are operating in each city.
Group the states and find how many active labs are operating in each city.
Find all the point of contacts. Find how many lab facilities each one handles.
Find the current status of lab facilities under each point of contacts.
Find the year in which they have made the last update.
Find the number of centers that begin between 1960 - 1969, 1970 - 1979, 1980 - 1989, 1990 - 1999, and 2000 and beyond

1.Find all the agencies that house a NASA Lab facility.
End of explanation
"""


df['Center'].value_counts()

"""
Explanation: 2. Find the different centers that run a NASA lab, and their count.
End of explanation
"""


df['Status'].value_counts()

"""
Explanation: 3. List the status of the lab facilities and their count?
End of explanation
"""


print("There are 388 active lab facilities in the US")

"""
Explanation: 4. Find how many active labs are operating today.
End of explanation
"""


df['State'].value_counts()

print("Alabama has the highest number of NASA Lab facilities in the country.")

"""
Explanation: 5. Which of the US states has the highest number of NASA Lab facilities ?
End of explanation
"""


print("Alabama has the highest number of NASA Lab facilities in the country")

"""
Explanation: 6. Which of the US states has the lowest number of NASA Lab facilities ?
End of explanation
"""


df.groupby("Agency")['Center'].value_counts()

"""
Explanation: 7. Group them by agencies, and count the centers operating under each agency.
End of explanation
"""


df.groupby("Agency")['Status'].value_counts()

"""
Explanation: 8. Group them by centers, and discover how many active labs are operating under each of them.
End of explanation
"""


df['City'].value_counts()

"""
Explanation: 9. Find all the cities with a Lab facility. Group them and find how many active labs are operating in each city.
End of explanation
"""


df.groupby("City")['Status'].value_counts()

"""
Explanation: 10. Find all the cities with a Lab facility. Group them and find how many active labs are operating in each city.
End of explanation
"""


state= df.groupby("State")['Status'].value_counts()
state

"""
Explanation: 11. Group the states and find how many active labs are operating in each city
End of explanation
"""


df['Contact'].value_counts()

"""
Explanation: 12. Find all the point of contacts. Find how many lab facilities each one handles.
End of explanation
"""


df.groupby("Contact")['Status'].value_counts()

"""
Explanation: 13.Find all the point of contacts. Find various status of lab facilities.
End of explanation
"""


for x in (df['Last Update']):
    if isinstance(x, str):
        print(x)

dropped = df[df['Last Update'] != "300 E St, SW"]
for x in (dropped['Last Update']):
    if isinstance(x, str):
        print(x)

df['Last Update'].str[:5]
df

dropped.sort_values(by='Last Update',ascending=False).head(3)

"""
Explanation: 14. Sort by the year in which they have made the last update.
End of explanation
"""


year60 = df[(df['Occupied'] >= 1960) & (df['Occupied'] <=1969)]
year60

year60['Occupied'].value_counts()

print("There are", year60['Occupied'].value_counts().sum(), "Lab facilities started between 1960-1969")

year70 = df[(df['Occupied'] >= 1970) & (df['Occupied'] <=1979)]
year70

year70['Occupied'].value_counts()

print("There are", year70['Occupied'].value_counts().sum(), "Lab facilities started between 1970-1979")

year80 = df[(df['Occupied'] >= 1980) & (df['Occupied'] <=1989)]
year80

year80['Occupied'].value_counts()

print("There are", year80['Occupied'].value_counts().sum(), "Lab facilities started between 1980-1989")

year90 = df[(df['Occupied'] >= 1990) & (df['Occupied'] <=1999)]
year90

year90['Occupied'].value_counts()

print("There are", year90['Occupied'].value_counts().sum(), "Lab facilities started between 1990-1999")

year00 = df[(df['Occupied'] >= 2000) & (df['Occupied'] <=2009)]
year00

year00['Occupied'].value_counts()

print("There are", year00['Occupied'].value_counts().sum(), "Lab facilities started between 2000-2009")

year10 = df[(df['Occupied'] >= 2010) & (df['Occupied'] <=2017)]
year10

year10['Occupied'].value_counts()

year10['Facility']

print("There are only", year10['Occupied'].value_counts().sum(), "Lab facilities started since 2010")


"""
Explanation: 15. Find all the centers that begin between 1960 - 1969, 1970 - 1979, 1980 - 1989, 1990 - 1999, and 2000 and beyond
End of explanation
"""


df['State'].value_counts().plot(kind='bar', x='State')

"""
Explanation: Graph 1 - NASA Lab Center Distribution in Different States
End of explanation
"""


df['Agency'].value_counts().plot(kind='bar', x='Agency')

"""
Explanation: Graph 2 NASA Lab Facilities Distribution by Agencies
End of explanation
"""


df = pd.read_excel("year-num-nasa.xlsx")

df

df['Number'].plot(kind='pie', labels=df['Year'])

"""
Explanation: Graph 3 NASA Lab Facilities Started Over the Last 60 Years
End of explanation
"""


