<jupyter_start><jupyter_text>ETEE UFO Signtings AnalysisLet's learn how combining pandas with ipython interact makes for an easy to search dataframe.This example is similar to the Fudgemart Products exercise from before only it uses pandas as a UFO dataset.5 months of UFO sightings from 2016https://github.com/mafudge/datasets/tree/master/ufo-sightings    1. combine 5 months of ufo sightings into a single dataset    2. interact to filter/search dataframe        2.1 drop down of state        2.2.drop down of shape        2.3 text search in summary<jupyter_code># Figure out data frame
import pandas as pd
ufo1 = pd.read_csv(f'https://raw.githubusercontent.com/mafudge/datasets/master/ufo-sightings/ufo-sightings-2016-01.csv')
ufo1
ufo2 = pd.read_csv(f'https://raw.githubusercontent.com/mafudge/datasets/master/ufo-sightings/ufo-sightings-2016-02.csv')
ufo2
ufom = ufo1.append(ufo2)
ufom
# index in wrong, need to reset
ufom = ufo1.append(ufo2,ignore_index=True)
ufom

# ready to make a function!
def loadUFODataFrame():
    ufo_df = pd.DataFrame()
    for i in range(1,6):
        ufo = pd.read_csv(f'https://raw.githubusercontent.com/mafudge/datasets/master/ufo-sightings/ufo-sightings-2016-0{i}.csv')
        ufo_df = ufo_df.append(ufo, ignore_index=True)
    return ufo_df

df = loadUFODataFrame()
# let's figure out a dropdown
df['State']

df['State'].unique()

# need to drop the nan
df['State'].dropna().unique()

# that's our list
states = list(df['State'].dropna().unique())
# need to add wildcard
states.insert(0,'**')
states.sort()
states<jupyter_output><empty_output><jupyter_text>Complete working code<jupyter_code>import requests 
import pandas as pd
from IPython.display import display,HTML
from ipywidgets import widgets, interact_manual
import warnings
warnings.filterwarnings('ignore')

def loadUFODataFrame():
    ufo_df = pd.DataFrame()
    for i in range(1,6):
        ufo = pd.read_csv(f'https://raw.githubusercontent.com/mafudge/datasets/master/ufo-sightings/ufo-sightings-2016-0{i}.csv')
        ufo_df = ufo_df.append(ufo, ignore_index=True)
    return ufo_df

df = loadUFODataFrame()
display(HTML("<h1>Search UFO Sightings<h1>"))
states = list(df['State'].dropna().unique())
states.sort()
states.insert(0,'*ANY*')
shapes = list(df['Shape'].dropna().unique())
shapes.sort()
shapes.insert(0, '*ANY*')
@interact_manual(state=states, shape=shapes, summary="")
def main(state,shape, summary):
    search_df = df
    if state != '*ANY*':
        search_df = search_df[ search_df.State == state ]
    if shape != '*ANY*':
        search_df = search_df[ search_df.Shape == shape ]
    if summary != "":    
        search_df = search_df[search_df.Summary.str.find(summary) >=0 ]
    display(search_df)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12972383720930233, 'fraction_numerical': 0.019622093023255814, 'mean_word_length': 4.506, 'pattern_counts': {'":': 1, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '188156', 'license': 'Apache-2.0', 'n_tokens_mistral': 1004, 'n_tokens_neox': 956, 'n_words': 221, 'path': 'lessons/12-pandas/EETE-UFO-Sightings-Analysis.ipynb', 'repo_name': 'IST256/fall2021', 'size': '2752'}