<jupyter_start><jupyter_text>Part-1 (Load Data)  1.Load Zoo data<jupyter_code>PATH_URL = "https://archive.ics.uci.edu/ml/machine-learning-databases/zoo/zoo.data"

# Save column names as a list
col_ls = ['animal name', 'hair', 'feathers','eggs','milk','airborne','aquatic','predator',
 'toothed','backbone','breathes','venomous','fins','legs','tail','domestic',
 'catsize','type']

# Pass in col_ls into names parameter to explicitly name each column
df_zoo = pd.read_csv(PATH_URL, 
                     names=col_ls
                    )
df_zoo.head()<jupyter_output><empty_output><jupyter_text>2.Load sentiment dataThis is sentiment data, include 2 columns: - **Text**: the sentences written in English- **Sentiment**: score is either 1 (for positive) or 0 (for negative)<jupyter_code>f = "" # string to store the text from file

resp = urlopen("https://archive.ics.uci.edu/ml/machine-learning-databases/00331/sentiment%20labelled%20sentences.zip") # open zip url  
zipfile = ZipFile(BytesIO(resp.read())) # read file 
for line in zipfile.open('sentiment labelled sentences/amazon_cells_labelled.txt'): # open files inside the zip
    f += line.decode('utf-8') # decode text using utf-8

file = f.split('\n') # split data line by line

for i in range(len(file)): 
  file[i] = file[i].split('\t') # split Text and Sentiment

# create data frame 
df_sentiment = pd.DataFrame.from_records(file[:-1],columns=['Text','Sentiment']) 
df_sentiment
df_sentiment.shape
df_sentiment.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 2 columns):
 #   Column     Non-Null Count  Dtype 
---  ------     --------------  ----- 
 0   Text       1000 non-null   object
 1   Sentiment  1000 non-null   object
dtypes: object(2)
memory usage: 15.8+ KB<jupyter_text>3.Load SMS Spam Collection data<jupyter_code>f = "" # string to store the text from file

resp = urlopen("https://archive.ics.uci.edu/ml/machine-learning-databases/00228/smsspamcollection.zip") # open zip url  
zipfile = ZipFile(BytesIO(resp.read())) # read file 
for line in zipfile.open('SMSSpamCollection'): # open files inside the zip
    f += line.decode('utf-8') # decode text using utf-8

file_ = f.split('\n') # split data line by line

for i in range(len(file_)): 
  file_[i] = file_[i].split('\t') # split Text and Sentiment

# create data frame 
df_emails = pd.DataFrame.from_records(file_[:-1],columns=['Sentiment','Text']) 
df_emails<jupyter_output><empty_output><jupyter_text>Part-2 (API)<jupyter_code>API = 'https://u50g7n0cbj.execute-api.us-east-1.amazonaws.com/v2/cities?limit=100&page=1&offset=0&sort=asc&country_id=SA&order_by=city'
data_SA = requests.get(API)
data_SA = data_SA.json()
df_SA = pd.DataFrame(data_SA['results'])
df_SA
# remove rows where city == N/A 
df_SA = df_SA[df_SA.city != 'N/A']
print('What cities are in the data?',df_SA['city'].values)
print('How many rows and columns are in the data?',df_SA.shape)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15425888665325285, 'fraction_numerical': 0.02079141515761234, 'mean_word_length': 4.607142857142857, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 4, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '539713', 'license': 'MIT', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1039, 'n_words': 240, 'path': 'Python/Week 2/Day6_Pandas.ipynb', 'repo_name': 'ZarahShibli/Data-Science-Bootcamp', 'size': '2982'}