Selecting only a single row per id - sql

I'd like to get back only one row per ID, even if there are multiple rows associated with an ID.
The scenario is that the data reflects a site selling land / properties, and that for each listing, there may be multiple images associated with each ID. I need only one.
Thank You.
As requested, sample data:
RowNumber ID UserID CountryID tbl_detailsID Name Description Price AddressLine1 AddressLine2 City State Zip AddressGPS Space Amenities Policies URL DateEntered DateExpires NumViews IsCompanyProperty EnforceMinStay IsOtherSite rate_Avg isFeatured DayPrice ImageURL Name check_in check_out currency bathroom_count pet unit_size elder handicap occupancy bedroom_count LinkURL smoking unit_size_Units property_Type children Minimum_stay Minimum_stay_Unit CountryName
2 247586 1 1 161398 Beautiful Oceanfront Home in Cambria California Located on the Central Coast of California 10 minutes from Hearst Castle.
Phone 1: Toll Free (800) 240-2277
Phone 2: (805) 927-0306 (California, USA)
direct email contact: debbie (#) maisonsdecambria.com
Leopold Cove" is a beautiful Oceanfront Home located on the Central Coast of California. It has fabulous ocean views and access to the water from a private stairway. The living area has large plate glass windows that feature 180 degree views of the Pacific Ocean. A comfortable platform style bed & a warm, cozy fireplace are also located in the living area so you can relax for hours, or even days, enjoying the beauty that surrounds you. There is a full kitchen & a separate bedroom with 2 twin beds. The property also has a picnic area & places to sit, perhaps with a good book & a glass of wine while you watch the sunset. If you are a nature lover, you will enjoy the otters, seals & birdlife that we are privileged to have so close to us. During the gray whale migration times, this is a p 2183 Sherwood Drive Cambria California 93428 35.544712|-121.095444 http://www.flipkey.com/cambria-vacation-rentals/p202618/ 2012-10-01 10:52:00 2012-10-15 10:52:00 0 0 0 703 5.0 0 NULL http://images1.flipkey.com/img/photos/302459/243298/large_302459-243298-007-1346943508.jpg Beautiful Oceanfront Home in Cambria California USD 1 Ask 0 Ask Ask 4 1 http://www.flipkey.com/cambria-vacation-rentals/p202618/ Ask House Ask 0 NULL United States
3 247586 1 1 161398 Beautiful Oceanfront Home in Cambria California Located on the Central Coast of California 10 minutes from Hearst Castle.
Phone 1: Toll Free (800) 240-2277
Phone 2: (805) 927-0306 (California, USA)
direct email contact: debbie (#) maisonsdecambria.com
Leopold Cove" is a beautiful Oceanfront Home located on the Central Coast of California. It has fabulous ocean views and access to the water from a private stairway. The living area has large plate glass windows that feature 180 degree views of the Pacific Ocean. A comfortable platform style bed & a warm, cozy fireplace are also located in the living area so you can relax for hours, or even days, enjoying the beauty that surrounds you. There is a full kitchen & a separate bedroom with 2 twin beds. The property also has a picnic area & places to sit, perhaps with a good book & a glass of wine while you watch the sunset. If you are a nature lover, you will enjoy the otters, seals & birdlife that we are privileged to have so close to us. During the gray whale migration times, this is a p 2183 Sherwood Drive Cambria California 93428 35.544712|-121.095444 http://www.flipkey.com/cambria-vacation-rentals/p202618/ 2012-10-01 10:52:00 2012-10-15 10:52:00 0 0 0 703 5.0 0 NULL http://images1.flipkey.com/img/photos/302459/243298/large_302459-243298-006-1346943508.jpg Beautiful Oceanfront Home in Cambria California USD 1 Ask 0 Ask Ask 4 1 http://www.flipkey.com/cambria-vacation-rentals/p202618/ Ask House Ask 0 NULL United States
4 247586 1 1 161398 Beautiful Oceanfront Home in Cambria California Located on the Central Coast of California 10 minutes from Hearst Castle.
Phone 1: Toll Free (800) 240-2277
Phone 2: (805) 927-0306 (California, USA)
direct email contact: debbie (#) maisonsdecambria.com
Leopold Cove" is a beautiful Oceanfront Home located on the Central Coast of California. It has fabulous ocean views and access to the water from a private stairway. The living area has large plate glass windows that feature 180 degree views of the Pacific Ocean. A comfortable platform style bed & a warm, cozy fireplace are also located in the living area so you can relax for hours, or even days, enjoying the beauty that surrounds you. There is a full kitchen & a separate bedroom with 2 twin beds. The property also has a picnic area & places to sit, perhaps with a good book & a glass of wine while you watch the sunset. If you are a nature lover, you will enjoy the otters, seals & birdlife that we are privileged to have so close to us. During the gray whale migration times, this is a p 2183 Sherwood Drive Cambria California 93428 35.544712|-121.095444 http://www.flipkey.com/cambria-vacation-rentals/p202618/ 2012-10-01 10:52:00 2012-10-15 10:52:00 0 0 0 703 5.0 0 NULL http://images1.flipkey.com/img/photos/302459/243298/large_302459-243298-005-1346943508.jpg Beautiful Oceanfront Home in Cambria California USD 1 Ask 0 Ask Ask 4 1 http://www.flipkey.com/cambria-vacation-rentals/p202618/ Ask House Ask 0 NULL United States
5 247586 1 1 161398 Beautiful Oceanfront Home in Cambria California Located on the Central Coast of California 10 minutes from Hearst Castle.
Phone 1: Toll Free (800) 240-2277
Phone 2: (805) 927-0306 (California, USA)
direct email contact: debbie (#) maisonsdecambria.com
Leopold Cove" is a beautiful Oceanfront Home located on the Central Coast of California. It has fabulous ocean views and access to the water from a private stairway. The living area has large plate glass windows that feature 180 degree views of the Pacific Ocean. A comfortable platform style bed & a warm, cozy fireplace are also located in the living area so you can relax for hours, or even days, enjoying the beauty that surrounds you. There is a full kitchen & a separate bedroom with 2 twin beds. The property also has a picnic area & places to sit, perhaps with a good book & a glass of wine while you watch the sunset. If you are a nature lover, you will enjoy the otters, seals & birdlife that we are privileged to have so close to us. During the gray whale migration times, this is a p 2183 Sherwood Drive Cambria California 93428 35.544712|-121.095444 http://www.flipkey.com/cambria-vacation-rentals/p202618/ 2012-10-01 10:52:00 2012-10-15 10:52:00 0 0 0 703 5.0 0 NULL http://images1.flipkey.com/img/photos/302459/243298/large_302459-243298-004-1346943508.jpg Beautiful Oceanfront Home in Cambria California USD 1 Ask 0 Ask Ask 4 1 http://www.flipkey.com/cambria-vacation-rentals/p202618/ Ask House Ask 0 NULL United States
6 247586 1 1 161398 Beautiful Oceanfront Home in Cambria California Located on the Central Coast of California 10 minutes from Hearst Castle.
Phone 1: Toll Free (800) 240-2277
Phone 2: (805) 927-0306 (California, USA)
direct email contact: debbie (#) maisonsdecambria.com
Leopold Cove" is a beautiful Oceanfront Home located on the Central Coast of California. It has fabulous ocean views and access to the water from a private stairway. The living area has large plate glass windows that feature 180 degree views of the Pacific Ocean. A comfortable platform style bed & a warm, cozy fireplace are also located in the living area so you can relax for hours, or even days, enjoying the beauty that surrounds you. There is a full kitchen & a separate bedroom with 2 twin beds. The property also has a picnic area & places to sit, perhaps with a good book & a glass of wine while you watch the sunset. If you are a nature lover, you will enjoy the otters, seals & birdlife that we are privileged to have so close to us. During the gray whale migration times, this is a p 2183 Sherwood Drive Cambria California 93428 35.544712|-121.095444 http://www.flipkey.com/cambria-vacation-rentals/p202618/ 2012-10-01 10:52:00 2012-10-15 10:52:00 0 0 0 703 5.0 0 NULL http://images1.flipkey.com/img/photos/302459/243298/large_302459-243298-003-1346943508.jpg Beautiful Oceanfront Home in Cambria California USD 1 Ask 0 Ask Ask 4 1 http://www.flipkey.com/cambria-vacation-rentals/p202618/ Ask House Ask 0 NULL United States
7 247586 1 1 161398 Beautiful Oceanfront Home in Cambria California Located on the Central Coast of California 10 minutes from Hearst Castle.
Phone 1: Toll Free (800) 240-2277
Phone 2: (805) 927-0306 (California, USA)
direct email contact: debbie (#) maisonsdecambria.com
Leopold Cove" is a beautiful Oceanfront Home located on the Central Coast of California. It has fabulous ocean views and access to the water from a private stairway. The living area has large plate glass windows that feature 180 degree views of the Pacific Ocean. A comfortable platform style bed & a warm, cozy fireplace are also located in the living area so you can relax for hours, or even days, enjoying the beauty that surrounds you. There is a full kitchen & a separate bedroom with 2 twin beds. The property also has a picnic area & places to sit, perhaps with a good book & a glass of wine while you watch the sunset. If you are a nature lover, you will enjoy the otters, seals & birdlife that we are privileged to have so close to us. During the gray whale migration times, this is a p 2183 Sherwood Drive Cambria California 93428 35.544712|-121.095444 http://www.flipkey.com/cambria-vacation-rentals/p202618/ 2012-10-01 10:52:00 2012-10-15 10:52:00 0 0 0 703 5.0 0 NULL http://images1.flipkey.com/img/photos/302459/243298/large_302459-243298-002-1346943508.jpg Beautiful Oceanfront Home in Cambria California USD 1 Ask 0 Ask Ask 4 1 http://www.flipkey.com/cambria-vacation-rentals/p202618/ Ask House Ask 0 NULL United States
8 247586 1 1 161398 Beautiful Oceanfront Home in Cambria California Located on the Central Coast of California 10 minutes from Hearst Castle.
Phone 1: Toll Free (800) 240-2277
Phone 2: (805) 927-0306 (California, USA)
direct email contact: debbie (#) maisonsdecambria.com
Leopold Cove" is a beautiful Oceanfront Home located on the Central Coast of California. It has fabulous ocean views and access to the water from a private stairway. The living area has large plate glass windows that feature 180 degree views of the Pacific Ocean. A comfortable platform style bed & a warm, cozy fireplace are also located in the living area so you can relax for hours, or even days, enjoying the beauty that surrounds you. There is a full kitchen & a separate bedroom with 2 twin beds. The property also has a picnic area & places to sit, perhaps with a good book & a glass of wine while you watch the sunset. If you are a nature lover, you will enjoy the otters, seals & birdlife that we are privileged to have so close to us. During the gray whale migration times, this is a p 2183 Sherwood Drive Cambria California 93428 35.544712|-121.095444 http://www.flipkey.com/cambria-vacation-rentals/p202618/ 2012-10-01 10:52:00 2012-10-15 10:52:00 0 0 0 703 5.0 0 NULL http://images1.flipkey.com/img/photos/302459/243298/large_302459-243298-001-1346943508.jpg Beautiful Oceanfront Home in Cambria California USD 1 Ask 0 Ask Ask 4 1 http://www.flipkey.com/cambria-vacation-rentals/p202618/ Ask House Ask 0 NULL United States
And the Omni-query I that I am constructing to replace a few hundred lines of temp tables:
SELECT DISTINCT ROW_NUMBER() OVER(ORDER BY tbl_Properties.ID DESC) AS [RowNumber], tbl_Properties.ID, tbl_Properties.UserID, tbl_Properties.CountryID, tbl_Properties.tbl_detailsID, tbl_Properties.Name,
tbl_Properties.[Description], tbl_Properties.Price, tbl_Properties.AddressLine1, tbl_Properties.AddressLine2, tbl_Properties.City, tbl_Properties.[State], tbl_Properties.Zip, tbl_Properties.AddressGPS,
tbl_Properties.[Space],
tbl_Properties.Amenities,
tbl_Properties.Policies,
tbl_Properties.URL,
tbl_Properties.DateEntered,
tbl_Properties.DateExpires,
tbl_Properties.NumViews,
tbl_Properties.IsCompanyProperty,
tbl_Properties.EnforceMinStay,
tbl_Properties.IsOtherSite,
tbl_Properties.rate_Avg,
tbl_Properties.isFeatured,
tbl_Properties.DayPrice,
tbl_Images.ImageURL,
tbl_Details.Name,
tbl_Details.check_in,
tbl_Details.check_out,
tbl_Details.currency,
tbl_Details.bathroom_count,
tbl_Details.pet,
tbl_Details.unit_size,
tbl_Details.elder,
tbl_Details.handicap,
tbl_Details.occupancy,
tbl_Details.bedroom_count,
tbl_Details.url As [LinkURL],
tbl_Details.smoking,
tbl_Details.unit_size_Units,
tbl_Details.property_Type,
tbl_Details.children,
tbl_Details.Minimum_stay,
tbl_Details.Minimum_stay_Unit,
tbl_Countries.Name As [CountryName]
FROM [tbl_Details]
INNER JOIN [tbl_Properties] ON [tbl_Details].[detailsID] = [tbl_Properties].[tbl_detailsID]
INNER JOIN [tbl_Images] ON [tbl_Images].PropertyID = [tbl_Properties].ID
INNER JOIN [tbl_Countries] ON [tbl_Countries].ID = [tbl_Properties].CountryID
The query itself is, of course, not finished yet.

If your SQLServer version supports row_number() OVER (2008,2012 support)
select * from
(select t.*,
row_number() over (partition by id order by id) as rownumber from t
) t1
where t1.rownumber=1
Here is the SQLFiddle example

Since there's no sample data you'll need to bend this response to suit your needs
select
Listings.*, SingleImage.Column1, SingleImage.Column2
from Listings
cross apply (
select top 1 *
from Images
where Listings.ListingID = Images.ListingID
) SingleImage
That needs SQL 2005 or newer (for the "cross apply" to work)
There are ways to make it work in SQL 2000 too but they're not as efficient

try this:
SELECT TOP 1 * FROM
imagestable
WHERE imagestable.landID = <theID>
This will return the first image in the table that belongs to the property.
You can INNER JOIN this query with your property table if you want to return all property info as a single record.

In SQL Server 2005+ you can use this
use tempdb
go
create table tbl (id int, s varchar(50))
insert into tbl values (1,'qwe'),(1,'asd'), (1,'qwff'),(2,'ert'),(2,'ykf'),(3,'')
;with cte
AS
(
SELECT id,s, ROW_NUMBER() OVER (PARTITION BY id ORDER BY s ) n
FROM tbl
)
SELECT id,s
FROM CTE
WHERE n=1
drop table tbl

Related

Scraping contents of news articles

I was able to scrape the title, date, links, and content of news on these links: https://www.news24.com/news24/southafrica/crime-and-courts and https://www.news24.com/news24/southafrica/education. The output is saved in an excel file. However, I noticed that not all the contents inside the articles were scrapped. I have tried different methods on my "Getting content section of my code" Any help with this will be appreciate. Below is my code:
import sys, time
from bs4 import BeautifulSoup
import requests
import pandas as pd
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from datetime import timedelta
art_title = [] # to store the titles of all news article
art_date = [] # to store the dates of all news article
art_link = [] # to store the links of all news article
pagesToGet = ['southafrica/crime-and-courts', 'southafrica/education']
for i in range(0, len(pagesToGet)):
print('processing page : \n')
url = 'https://www.news24.com/news24/'+str(pagesToGet[i])
print(url)
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
try:
driver.get("https://www.news24.com/news24/" +str(pagesToGet[i]))
except Exception as e:
error_type, error_obj, error_info = sys.exc_info()
print('ERROR FOR LINK:', url)
print(error_type, 'Line:', error_info.tb_lineno)
continue
time.sleep(3)
scroll_pause_time = 1
screen_height = driver.execute_script("return window.screen.height;")
i = 1
while True:
driver.execute_script("window.scrollTo(0, {screen_height}{i});".format(screen_height=screen_height, i=i))
i += 1
time.sleep(scroll_pause_time)
scroll_height = driver.execute_script("return document.body.scrollHeight;")
if (screen_height) * i > scroll_height:
break
soup = BeautifulSoup(driver.page_source, 'html.parser')
news = soup.find_all('article', attrs={'class': 'article-item'})
print(len(news))
# Getting titles, dates, and links
for j in news:
titles = j.select_one('.article-item__title span')
title = titles.text.strip()
dates = j.find('p', attrs={'class': 'article-item__date'})
date = dates.text.strip()
address = j.find('a').get('href')
news_link = 'https://www.news24.com' + address
art_title.append(title)
art_date.append(date)
art_link.append(news_link)
df = pd.DataFrame({'Article_Title': art_title, 'Date': art_date, 'Source': art_link})
# Getting Content Section
news_articles = [] # to store the content of each news artcle
news_count = 0
for link in df['Source']:
print('\n')
start_time = time.monotonic()
print('Article No. ', news_count)
print('Link: ', link)
# Countermeasure for broken links
try:
if requests.get(link):
news_response = requests.get(link)
else:
print("")
except requests.exceptions.ConnectionError:
news_response = 'N/A'
# Auto sleep trigger after saving every 300 articles
sleep_time = ['100', '200', '300', '400', '500']
if news_count in sleep_time:
time.sleep(12)
else:
""
try:
if news_response.text:
news_data = news_response.text
else:
print('')
except AttributeError:
news_data = 'N/A'
news_soup = BeautifulSoup(news_data, 'html.parser')
try:
if news_soup.find('div', {'class': 'article__body'}):
art_cont = news_soup.find('div','article__body')
art = []
article_text = [i.text.strip().replace("\xa0", " ") for i in art_cont.findAll('p')]
art.append(article_text)
else:
print('')
except AttributeError:
article = 'N/A'
print('\n')
news_count += 1
news_articles.append(art)
end_time = time.monotonic()
print(timedelta(seconds=end_time - start_time))
print('\n')
# Create a column to add all the scraped text
df['News'] = news_articles
df.drop_duplicates(subset ="Source", keep = False, inplace = True)
# Dont store links
df.drop(columns=['Source'], axis=1, inplace=True)
df.to_excel('SA_news24_3.xlsx')
driver.quit()
I tried the following code in the Getting Content Section as well. However, it produced the same output.
article_text = [i.get_text(strip=True).replace("\xa0", " ") for i in art_cont.findAll('p')]
The site has various types of URLs so your code was omitting them since they found it malformed or some had to be subscribed to read.For the ones that has to be subscribed to read i have added "Login to read" followers by the link in articles . I ran this code till article number 670 and it didn't give any error. I had to change it from .xlsx to .csv since it was giving an error of openpyxl in python 3.11.0.
Full Code
import time
import sys
from datetime import timedelta
import pandas as pd
from bs4 import BeautifulSoup
import requests
import json
art_title = [] # to store the titles of all news article
art_date = [] # to store the dates of all news article
art_link = [] # to store the links of all news article
pagesToGet = ['southafrica/crime-and-courts',
'southafrica/education', 'places/gauteng']
for i in range(0, len(pagesToGet)):
print('processing page : \n')
if "places" in pagesToGet[I]:
url = f"https://news24.com/api/article/loadmore/tag?tagType=places&tag={pagesToGet[i].split('/')[1]}&pagenumber=1&pagesize=100&ishomepage=false&ismobile=false"
else:
url = f"https://news24.com/api/article/loadmore/news24/{pagesToGet[i]}?pagenumber=1&pagesize=1200&ishomepage=false&ismobile=false"
print(url)
r = requests.get(url)
soup = BeautifulSoup(r.json()["htmlContent"], 'html.parser')
news = soup.find_all('article', attrs={'class': 'article-item'})
print(len(news))
# Getting titles, dates, and links
for j in news:
titles = j.select_one('.article-item__title span')
title = titles.text.strip()
dates = j.find('p', attrs={'class': 'article-item__date'})
date = dates.text.strip()
address = j.find('a').get('href')
# Countermeasure for links with full url
if "https://" in address:
news_link = address
else:
news_link = 'https://www.news24.com' + address
art_title.append(title)
art_date.append(date)
art_link.append(news_link)
df = pd.DataFrame({'Article_Title': art_title,
'Date': art_date, 'Source': art_link})
# Getting Content Section
news_articles = [] # to store the content of each news artcle
news_count = 0
for link in df['Source']:
start_time = time.monotonic()
print('Article No. ', news_count)
print('Link: ', link)
news_response = requests.get(link)
news_data = news_response.content
news_soup = BeautifulSoup(news_data, 'html.parser')
art_cont = news_soup.find('div', 'article__body')
# Countermeasure for links with subscribe form
try:
try:
article = art_cont.text.split("Newsletter")[
0]+art_cont.text.split("Sign up")[1]
except:
article = art_cont.text
article = " ".join((article).strip().split())
except:
article = f"Login to read {link}"
news_count += 1
news_articles.append(article)
end_time = time.monotonic()
print(timedelta(seconds=end_time - start_time))
print('\n')
# Create a column to add all the scraped text
df['News'] = news_articles
df.drop_duplicates(subset="Source", keep=False, inplace=True)
# Dont store links
df.drop(columns=['Source'], axis=1, inplace=True)
df.to_csv('SA_news24_3.csv')
Output
,Article_Title,Date,News
0,Pastor gets double life sentence plus two 15-year terms for rape and murder of women,2h ago,"A pastor has been sentenced to two life sentences and two 15-year jail terms for rape and murder His modus operandi was to take the women to secluded areas before raping them and tying them to trees.One woman managed to escape after she was raped but the bodies of two others were found tied to the trees.The North West High Court has sentenced a 50-year-old pastor to two life terms behind bars and two 15-year jail terms for rape and murder.Lucas Chauke, 50, was sentenced on Monday for the crimes, which were committed in 2017 and 2018 in Temba in the North West.According to North West National Prosecuting Authority spokesperson Henry Mamothame, Chauke's first victim was a 53-year-old woman.He said Chauke pretended that he would assist the woman with her spirituality and took her to a secluded place near to a dam.""Upon arrival, he repeatedly raped her and subsequently tied her to a tree before fleeing the scene,"" Mamothame said. The woman managed to untie herself and ran to seek help. She reported the incident to the police, who then started searching for Chauke.READ | Kidnappings doubled nationally: over 4 000 cases reported to police from July to SeptemberOn 10 May the following year, Chauke pounced on his second victim - a 55-year-old woman.He took her to the same secluded area next to the dam, raped her and tied her to a tree before fleeing. This time his victim was unable to free herself.Her decomposed body was later found, still tied to the tree, Mamothame said. His third victim was targeted months later, on 3 August, in the same area. According to Mamothame, Chauke attempted to rape her but failed.""He then tied her to a tree and left her to die,"" he said. Chauke was charged in connection with her murder.He was linked to the crimes via DNA.READ | 'These are not pets': Man gives away his two pit bulls after news of child mauled to deathIn aggravation of his sentence, State advocate Benny Kalakgosi urged the court not to deviate from the prescribed minimum sentences, saying that the offences Chauke had committed were serious.""He further argued that Chauke took advantage of unsuspecting women, who trusted him as a pastor but instead, [he] took advantage of their vulnerability,"" Mamothame said. Judge Frances Snyman agreed with the State and described Chauke's actions as horrific.The judge also alluded to the position of trust that he abused, Mamothame said.Chauke was sentenced to life for the rape of the first victim, 15 years for the rape of the second victim and life for her murder, as well as 15 years for her murder. He was also declared unfit to possess a firearm."
1,'I am innocent': Alleged July unrest instigator Ngizwe Mchunu pleads not guilty,4h ago,"Former Ukhozi FM DJ Ngizwe Mchunu has denied inciting the July 2022 unrest.Mchunu pleaded not guilty to charges that stem from the incitement allegations.He also claimed he had permission to travel to Gauteng for work during the Covid-19 lockdown.""They are lying. I know nothing about those charges,"" alleged July unrest instigator, former Ukhozi FM DJ Ngizwe Brian Mchunu, told the Randburg Magistrate's Court when his trial started on Tuesday.Mchunu pleaded not guilty to the charges against him, which stems from allegations that he incited public violence, leading to the destruction of property, and convened a gathering in contravening of Covid-19 lockdown regulations after the detention of former president Jacob Zuma in July last year.In his plea statement, Mchunu said all charges were explained to him.""I am a radio and television personality. I'm also a poet and cultural activist. In 2020, I established my online radio.READ | July unrest instigators could face terrorism-related charges""On 11 July 2021, I sent invitations to journalists to discuss the then-current affairs. At the time, it was during the arrest of Zuma.""I held a media briefing at a hotel in Bryanston to show concerns over Zuma's arrest. Zuma is my neighbour [in Nkandla]. In my African culture, I regard him as my father.""Mchunu continued that he was not unhappy about Zuma's arrest but added: ""I didn't condone any violence. I pleaded with fellow Africans to stop destroying infrastructure. I didn't incite any violence.I said to them, 'My brothers and sisters, I'm begging you as we are destroying our country.'""He added:They are lying. I know nothing about those charges. I am innocent. He also claimed that he had permission to travel to Gauteng for work during the lockdown.The hearing continues."
2,Jukskei River baptism drownings: Pastor of informal 'church' goes to ground,5h ago,"A pastor of the church where congregants drowned during a baptism ceremony has gone to ground.Johannesburg Emergency Medical Services said his identity was not known.So far, 14 bodies have been retrieved from the river.According to Johannesburg Emergency Medical Services (EMS), 13 of the 14 bodies retrieved from the Jukskei River have been positively identified.The bodies are of congregants who were swept away during a baptism ceremony on Saturday evening in Alexandra.The search for the other missing bodies continues.Reports are that the pastor of the church survived the flash flood after congregants rescued him.READ | Jukskei River baptism: Families gather at mortuary to identify loved onesEMS spokesperson Robert Mulaudzi said they had been in contact with the pastor since the day of the tragedy, but that they had since lost contact with him.It is alleged that the pastor was not running a formal church, but rather used the Jukskei River as a place to perform rituals for people who came to him for consultations. At this stage, his identity is not known, and because his was not a formal church, Mulaudzi could not confirm the number of people who could have been attending the ceremony.Speaking to the media outside the Sandton fire station on Tuesday morning, a member of the rescue team, Xolile Khumalo, said: Thirteen out of the 14 bodies retrieved have been identified, and the one has not been identified yet.She said their team would continue with the search. ""Three families have since come forward to confirm missing persons, and while we cannot be certain that the exact number of bodies missing is three, we will continue with our search."""
3,Six-month-old infant ‘abducted’ in Somerset West CBD,9h ago,"Authorities are on high alert after a baby was allegedly abducted in Somerset West on Monday.The alleged incident occurred around lunchtime, but was only reported to Somerset West police around 22:00. According to Sergeant Suzan Jantjies, spokesperson for Somerset West police, the six-month-old baby boy was taken around 13:00. It is believed the infant’s mother, a 22-year-old from Nomzamo, entrusted a fellow community member and mother with the care of her child before leaving for work on Monday morning. However, when she returned home from work, she was informed that the child was taken. Police were apparently informed that the carer, the infant and her nine-year-old child had travelled to Somerset West CBD to attend to Sassa matters. She allegedly stopped by a liquor store in Victoria Street and asked an unknown woman to keep the baby and watch over her child. After purchasing what was needed and exiting the store, she realised the woman and the children were missing. A case of abduction was opened and is being investigated by the police’s Family Violence, Child Protection and Sexual Offences (FCS) unit. Police obtained security footage which shows the alleged abductor getting into a taxi and making off with the children. The older child was apparently dropped off close to her home and safely returned. However, the baby has still not been found. According to a spokesperson, FCS police members prioritised investigations immediately after the case was reported late last night and descended on the local township, where they made contact with the visibly “traumatised” parent and obtained statements until the early hours of Tuesday morning – all in hopes of locating the child and the alleged suspect.Authorities are searching for what is believed to be a foreign national woman with braids, speaking isiZulu.Anyone with information which could aid the investigation and search, is urged to call Captain Trevor Nash of FCS on 082 301 8910."
4,Have you herd: Dubai businessman didn't know Ramaphosa owned Phala Phala buffalo he bought - report,8h ago,"A Dubai businessman who bought buffaloes at Phala Phala farm reportedly claims he did not know the deal was with President Cyril Ramaphosa.Hazim Mustafa also claimed he was expecting to be refunded for the livestock after the animals were not delivered.He reportedly brought the cash into the country via OR Tambo International Airport, and claims he declared it.A Dubai businessman who reportedly bought 20 buffaloes from President Cyril Ramaphosa's Phala Phala farm claims that he didn't know the deal with was with the president, according to a report.Sky News reported that Hazim Mustafa, who reportedly paid $580 000 (R10 million) in cash for the 20 buffaloes from Ramaphosa's farm in December 2019, said initially he didn't know who the animals belonged to.A panel headed by former chief justice Sandile Ngcobo released a report last week after conducting a probe into allegations of a cover-up of a theft at the farm in February 2020.READ | Ramaphosa wins crucial NEC debate as parliamentary vote on Phala Phala report delayed by a weekThe panel found that there was a case for Ramaphosa to answer and that he may have violated the law and involved himself in a conflict between his official duties and his private business.In a statement to the panel, Mustafa was identified as the source of the more than $500 000 (R9 million) that was stolen from the farm. Among the evidence was a receipt for $580 000 that a Phala Phala employee had written to ""Mr Hazim"".According to Sky News, Mustafa said he celebrated Christmas and his wife's birthday in Limpopo in 2019, and that he dealt with a broker when he bought the animals.He reportedly said the animals were to be prepared for export, but they were never delivered due to the Covid-19 lockdown. He understood he would be refunded after the delays.He also reportedly brought the cash into the country through OR Tambo International Airport and said he declared it. Mustafa also told Sky News that the amount was ""nothing for a businessman like [him]"".READ | Here's the Sudanese millionaire - and his Gucci wife - who bought Ramaphosa's buffaloThe businessman is the owner Sudanese football club Al Merrikh SC. He is married to Bianca O'Donoghue, who hails from KwaZulu-Natal. O'Donoghue regularly takes to social media to post snaps of a life of wealth – including several pictures in designer labels and next to a purple Rolls Royce Cullinan, a luxury SUV worth approximately R5.5 million.Sudanese businessman Hazim Mustafa with his South African-born wife, Bianca O'Donoghue.Facebook PHOTO: Bianca O'Donoghue/Facebook News24 previously reported that he also had ties to former Sudanese president, Omar al-Bashir.There have been calls for Ramaphosa to step down following the saga. A motion of no confidence is expected to be submitted in Parliament.He denied any wrongdoing and said the ANC's national executive committee (NEC) would decide his fate.Do you have a tipoff or any information that could help shape this story? Email tips#24.com"
5,Hefty prison sentence for man who killed stranded KZN cop while pretending to offer help,9h ago,"Two men have been sentenced – one for the murder of a KwaZulu-Natal police officer, and the other for an attempt to rob the officer.Sergeant Mzamiseni Mbele was murdered in Weenen in April last year.He was attacked and robbed when his car broke down on the highway while he was on his way home.A man who murdered a KwaZulu-Natal police officer, after pretending that he wanted to help him with his broken-down car, has been jailed.A second man, who was only convicted of an attempt to rob the officer, has also been sentenced to imprisonment.On Friday, the KwaZulu-Natal High Court in Madadeni sentenced Sboniso Linda, 36, to an effective 25 years' imprisonment, and Nkanyiso Mungwe, 25, to five years' imprisonment.READ | Alleged house robber shot after attack at off-duty cop's homeAccording to Hawks spokesperson, Captain Simphiwe Mhlongo, 39-year-old Sergeant Mzamiseni Mbele, who was stationed at the Msinga police station, was on his way home in April last year when his car broke down on the R74 highway in Weenen.Mbele let his wife know that the car had broken down. While stationary on the road, Linda and Mungwe approached him and offered to help.Mhlongo said: All of a sudden, [they] severely assaulted Mbele. They robbed him of his belongings and fled the scene. A farm worker found Mbele's body the next dayA case of murder was reported at the Weenen police station and the Hawks took over the investigation.The men were arrested.""Their bail [application] was successfully opposed and they appeared in court several times until they were found guilty,"" Mhlongo added.How safe is your neighbourhood? Find out by using News24's CrimeCheckLinda was sentenced to 20 years' imprisonment for murder and 10 years' imprisonment for robbery with aggravating circumstances. Half of the robbery sentence has to be served concurrently, leaving Linda with an effective sentence of 25 years.Mungwe was sentenced to five years' imprisonment for attempted robbery with aggravating circumstances."

How to extract text "lower" in a div

I am trying to extract all locations from a web page that are grouped into a large id=results div.
https://www.dynacast.com/en-gb/discover-dynacast/locations
My current code produces an empty list that I cannot interact with:
browser = mechanicalsoup.StatefulBrowser(soup_config={'features': 'lxml'}
locations_page = browser.page
locations_list = locations_page.find_all("div", id="location-list")
for locations_grid in locations_list:
grid = locations_grid.find_all_next("div", class_="grid-4")
print(grid)
Output = []
My aim is to extract all the text from this locations table (North America, Europe etc.) and the locations within the continents and append it to a list. Thank you in advance.
The page is dynamic so you won't get that html from a simple request. My suggestion is just get the data in json format from the api and can use pandas to normalize it:
import requests
import pandas as pd
url = 'https://www.dynacast.com/api/sitecore/Location/LocationsByServiceAjax'
payload = {
'serviceId': '',
'contextItemId': 'a9640857-ede5-47b3-a692-1606ee151d7c'}
jsonData = requests.get(url, params=payload).json()
df = pd.json_normalize(jsonData)
Output: 1st 5 of 15 rows below
print(df.head(5).to_string())
Id LocationName LocationAddress Phone Continent Country DirectionsLink CountryUrl Content Latitude Longitude SummaryContent SalesPhone ItemUrl IsFeatured
0 7ec388a8-adfa-4652-90b7-af1a089dfba1 Dynacast Tunisia Parc d'Activités Economiques de Bizerte\r\nSite de Menzel Bourguiba II BP 130\r\n7050 Menzel Bourguiba\r\nTunisie +216 72418363 Africa Tunisia https://www.google.com/maps?daddr=Parc+d%27Activit%C3%A9s+Economiques%2BMenzel+Bourguiba%2BBizerte%2BTunisia <p>Dynacast acquired Taurus Tunisia in 2016; it is located in Menzel Bourguiba, Bizerte, Tunisia just 30 minutes from the Tunis International Airport. This 1,900m<sup>2</sup> facility specializes in precision zinc die casting. Additional details about this location include:</p>\n<ul>\n<li>12 conventional zinc die casting machines ranging from 20T to 135T</li>\n<li>Production range from 0.5g to 0.9 kg</li>\n<li>Assembly operations </li>\n<li>In-house tool maintenance and repair</li>\n<li>Wide range of secondary operations and surface finishes including milling, thread cutting, sand blasting, and tumbling</li>\n</ul> 37.1450007 9.8045612 <p>Dynacast acquired Taurus Tunisia in 2016; it is located in Menzel Bourguiba, Bizerte, Tunisia. This 1,900m<sup>2</sup> facility specializes in precision zinc die casting.</p> /en/discover-dynacast/locations/dynacast-tunisia False
1 a7138364-2693-45b7-a886-4d526a325428 Sundaram Dynacast India No. 25 A/2, Sidco Industrial Park\nNorth Phase, Ambattur\nChennai, Tamil Nadu 600098 +91.44.2625.9169 Asia India https://www.google.com/maps?daddr=No.+25+A%2F2%2C+Sidco+Industrial+Park%2BChennai%2BTamil+Nadu%2BIndia <p>Sundaram Dynacast is a 68,000 square foot facility located in Ambattur, Chennai, India. The facility is the largest zinc high pressure hot chamber die caster in this area. Below are additional details about what is offered at this location:</p>\n<ul>\n<li>19 multi-slide proprietary zinc die casting machines ranging from 2.5 to 4.5 tons</li>\n<li>7 standard zinc die casting machines ranging from 25 to 63 tons</li>\n<li>8 aluminum die casting machine ranging from 125T to 350 tons</li>\n<li>Precision tool building with in-house capabilities</li>\n<li>Wide range of secondary operations including CNC machining, tapping, reaming, drilling, and assembly available through certified/dedicated partners</li>\n<li>Wide range of surface finishes are available in-house including tumbling, polishing, shot blasting, de-burring etc.. Plating, powder coating etc. are supported through our certified partners</li>\n</ul>\n<p /> 13.1094448 80.1666248 <p>Sundaram Dynacast is a 68,000 square foot facility located in Ambattur, Chennai, India. The facility is the largest zinc high pressure hot chamber die caster in this area. </p> /en/discover-dynacast/locations/sundaram-dynacast-india False
2 a2129999-b0d7-458b-bdd4-ae8a15dd4276 Dynacast Singapore 6 Second Chin Bee Road\r\nJurong, 618773 65.6268.7644 ext. 135 Asia Singapore <p>Dynacast Singapore focuses on multi-slide zinc, conventional zinc, aluminum, and magnesium die casting. Below are additional details about what is offered at the Singapore location:</p>\n<ul>\n<li>40 multi-slide proprietary zinc die casting machines ranging from 4 to 27 tons</li>\n<li>1 standard zinc die casting machines up to 125 tons</li>\n<li>4 aluminum die casting machines up to 135 tons</li>\n<li>1 multi-slide magnesium die casting machine up to 20 tons</li>\n<li>Precision tool building with in-house capabilities</li>\n<li>Wide range of secondary operations including CNC machining, tapping, reaming, and drilling available in house and through certified partners</li>\n<li>Design, prototyping, and modeling services</li>\n<li>Wide range of finishing surfaces available including tumbling, polishing, shot blasting and thermal de-burring</li>\n</ul>\n<p>www.dynacast.com.sg</p>\n<p><br /><strong>Dynacast Singapore works with OptiMIM, utilizing state-of-the-art metal injection molding technology to create high performing small precision metal components to almost any level of complexity and at virtually any volume.</strong></p> 1.332509 103.714238 <p>Dynacast Singapore focuses on multi-slide zinc, conventional zinc, aluminum, and magnesium die casting. </p> /en/discover-dynacast/locations/dynacast-singapore False
3 f2dd9429-d9d4-4028-b8ca-227972771980 Dynacast Tokyo (Regional Support Office) Azabu Green Terrace 5F\r\nMinamiazabu 3-20-1\r\nMinato-ku, Tokyo 106-0047 +03 6859-8512 Asia Japan <p>Dynacast Tokyo is a Regional Support Office that is strategically located to help with the demand for die casting components in the Asian market. Our sales team is available to help with any of your small precision component needs. </p>\n<p><a rel="noopener noreferrer" href="http://www.dynacast.jp" target="_blank">www.dynacast.jp</a></p> 35.649991 139.7307153 <p>Dynacast Tokyo is a sales office that is strategically located to help with the demand for die casting components in the Asian market. Our sales team is available to help with any of your small precision component needs. </p> /en/discover-dynacast/locations/dynacast-tokyo False
4 a4535e88-d1c3-4489-b351-cb75c4658f61 Dynacast Dongguan No. 88 Qiufu Road District\r\nFumin Industrial Park 2\r\nDalang, Dongguan, Guangdong 523778 86.769.8222.0638 (8801) Asia China https://www.google.com/maps?daddr=No.+88+Qiufu+Road+District%2BDalang%2C+Dongguan%2BGuangdong%2BChina <p>Dynacast Dongguan is a 14,000 square meter facility that is located in the heart of the Guangdong Province. The facility delivers high quality parts to the leading manufacturing hub in Southern China and focuses on zinc, aluminum, and magnesium die casting. Below are additional details about what is offered at the Dongguan location:</p>\n<ul>\n<li>28 zinc die casting machines ranging from 2 to 250 tons</li>\n<li>20 aluminum die casting machines ranging from 125 to 350 tons</li>\n<li>4 standard magnesium die casting machines ranging from 60 to 350 tons</li>\n<li>4 aluminum & magnesium die cast machines ranging from 60 to 350 tons </li>\n<li>2 standard plastic injection machines up to 100 tons</li>\n<li>Precision tool building with in-house capabilities</li>\n<li>Wide range of secondary operations including CNC machining, tapping, reaming, and drilling available in house and through certified partners</li>\n<li>Design, prototyping, and modeling services</li>\n<li>Wide range of finishing surfaces available including E-coating, electroless nickel plating, bright chrome, black chrome, spray painting, black anodising, micro-arc oxidation, copper nickle chrome, powder coating and passivation</li>\n</ul>\n<p>www.dynacast.cn</p>\n<p /> 22.9455755 113.9313944 <p>Dynacast Dongguan is a 14,000 square meter facility that is located in the heart of the Guangdong Province. The facility delivers high quality parts to the leading manufacturing hub in Southern China and focuses on zinc, aluminum, and magnesium die casting.</p> /en/discover-dynacast/locations/dynacast-dongguan False

TraMineR for time-use data with over hundred different activities

I'm trying to analyse sequences with TraMineR
UKTUS records people activities for every 10 minutes defined by the dataset as act1_1, act1_2,...,act1_144 variables (144 x 10 minutes).
Each time step (act1_1, act1_2, act1_3) is defined by one of the following code:
-1 Not applicable
0 Unspecified personal care
110 Sleep
111 Sleep: In bed not asleep
120 Sleep: Sick in bed
210 Eating
300 Other personal care: Unspecified other personal care
310 Other personal care: Wash and dress
390 Other personal care: Other specified personal care
1000 Unspecified employment
1100 Main job: unspecified main job
1110 Main job: Working time in main job
1120 Main job: Coffee and other breaks in main job
1210 Second job: Working time in second job
1220 Second job: Coffee and other breaks in second job
1300 Activities related to employment: Unspecified activities related to employment
1310 Activities related to employment: Lunch break
1390 Activities related to employment: Other specified activities related to employment
1391 Activities related to employment: Activities related to job seeking
1399 Activities related to employment: Other unspecified activities related to employment
2000 Study: Unspecified study school or university
2100 Study: Unspecified activities related to school or university
2110 Study: Classes and lectures
2120 Study: Homework
2190 Study: other specified activities related to school or university
2210 Free time study
3000 Unspecified household and family care
3100 Unspecified food management
3110 Food preparation and baking
3130 Dish washing
3140 Preserving
3190 Other specified food management
3200 Unspecified household upkeep
3210 Cleaning dwelling
3220 Cleaning yard
3230 Heating and water
3240 Arranging household goods and materials
3250 Disposal of waste
3290 Other or unspecified household upkeep
3300 Unspecified making and care for textiles
3310 Laundry
3320 Ironing
3330 Handicraft and producing textiles
3390 Other specified making and care for textiles
3410 Gardening
3420 Tending domestic animals
3430 Caring for pets
3440 Walking the dog
3490 Other specified gardening and pet care
3500 Unspecified construction and repairs
3510 House construction and renovation
3520 Repairs of dwelling
3530 Making repairing and maintaining equipment
3531 Woodcraft metalcraft sculpture and pottery
3539 Other specified making repairing and maintaining equipment
3540 Vehicle maintenance
3590 Other specified construction and repairs
3600 Unspecified shopping and services
3610 Unspecified shopping
3611 Shopping mainly for food
3612 Shopping mainly for clothing
3613 Shopping mainly related to accommodation
3614 Shopping or browsing at car boot sales or antique fairs
3615 Window shopping or other shopping as leisure
3619 Other specified shopping
3620 Commercial and administrative services
3630 Personal services
3690 Other specified shopping and services
3710 Household management not using the internet
3713 Shopping for and ordering clothing via the internet
3720 Unspecified household management using the internet
3721 Shopping for and ordering unspecified goods and services via the internet
3722 Shopping for and ordering food via the internet
3724 Shopping for and ordering goods and services related to accommodation via the internet
3725 Shopping for and ordering mass media via the internet
3726 Shopping for and ordering entertainment via the internet
3727 Banking and bill paying via the internet
3729 Other specified household management using the internet
3800 Unspecified childcare
3810 Unspecified physical care & supervision of a child
3811 Feeding the child
3819 Other and unspecified physical care & supervision of a child
3820 Teaching the child
3830 Reading playing and talking with child
3840 Accompanying child
3890 Other or unspecified childcare
3910 Unspecified help to a non-dependent eg injured adult household member
3911 Physical care of a non-dependent e.g. injured adult household member
3914 Accompanying a non-dependent adult household member e.g. to hospital
3919 Other specified help to a non-dependent adult household member
3920 Unspecified help to a dependent adult household member
3921 Physical care of a dependent adult household member e.g. Alzheimic parent
3924 Accompanying a dependent adult household member e.g. Alzheimic
3929 Other specified help to a dependent adult household member
4000 Unspecified volunteer work and meetings
4100 Unspecified organisational work
4110 Work for an organisation
4120 Volunteer work through an organisation
4190 Other specified organisational work
4200 Unspecified informal help to other households
4210 Food management as help to other households
4220 Household upkeep as help to other households
4230 Gardening and pet care as help to other households
4240 Construction and repairs as help to other households
4250 Shopping and services as help to other households
4260 Help to other households in employment and farming
4270 Unspecified childcare as help to other households
4271 Physical care and supervision of child as help to other household
4272 Teaching non-coresident child
4273 Reading playing & talking to non-coresident child
4274 Accompanying non-coresident child
4275 Physical care and supervision of own child as help to other household
4277 Reading playing & talking to own non-coresident child
4278 Accompanying own non-coresident child
4279 Other specified childcare as help to other household
4280 Unspecified help to an adult of another household
4281 Physical care and supervision of an adult as help to another household
4282 Accompanying an adult as help to another household
4283 Other specified help to an adult member of another household
4289 Other specified informal help to another household
4290 Other specified informal help
4300 Unspecified participatory activities
4310 Meetings
4320 Religious activities
4390 Other specified participatory activities
5000 Unspecified social life and entertainment
5100 Unspecified social life
5110 Socialising with family
5120 Visiting and receiving visitors
5130 Celebrations
5140 Telephone conversation
5190 Other specified social life
5200 Unspecified entertainment and culture
5210 Cinema
5220 Unspecified theatre or concerts
5221 Plays musicals or pantomimes
5222 Opera operetta or light opera
5223 Concerts or other performances of classical music
5224 Live music other than classical concerts opera and musicals
5225 Dance performances
5229 Other specified theatre or concerts
5230 Art exhibitions and museums
5240 Unspecified library
5241 Borrowing books records audiotapes videotapes CDs VDs etc. from a library
5242 Reference to books and other library materials within a library
5243 Using internet in the library
5244 Using computers in the library other than internet use
5245 Reading newspapers in a library
5249 Other specified library activities
5250 Sports events
5290 Other unspecified entertainment and culture
5291 Visiting a historical site
5292 Visiting a wildlife site
5293 Visiting a botanical site
5294 Visiting a leisure park
5295 Visiting an urban park playground designated play area
5299 Other or unspecified entertainment or culture
5310 Resting - Time out
6000 Unspecified sports and outdoor activities
6100 Unspecified physical exercise
6110 Walking and hiking
6111 Taking a walk or hike that lasts at least miles or 1 hour
6119 Other walk or hike
6120 Jogging and running
6130 Biking skiing and skating
6131 Biking
6132 Skiing or skating
6140 Unspecified ball games
6141 Indoor pairs or doubles games
6142 Indoor team games
6143 Outdoor pairs or doubles games
6144 Outdoor team games
6149 Other specified ball games
6150 Gymnastics
6160 Fitness
6170 Unspecified water sports
6171 Swimming
6179 Other specified water sports
6190 Other specified physical exercise
6200 Unspecified productive exercise
6210 Hunting and fishing
6220 Picking berries mushroom and herbs
6290 Other specified productive exercise
6310 Unspecified sports related activities
6311 Activities related to sports
6312 Activities related to productive exercise
7000 Unspecified hobbies games and computing
7100 Unspecified arts
7110 Unspecified visual arts
7111 Painting drawing or other graphic arts
7112 Making videos taking photographs or related photographic activities
7119 Other specified visual arts
7120 Unspecified performing arts
7121 Singing or other musical activities
7129 Other specified performing arts
7130 Literary arts
7140 Other specified arts
7150 Unspecified hobbies
7160 Collecting
7170 Correspondence
7190 Other specified or unspecified arts and hobbies
7220 Computing - programming
7230 Unspecified information by computing
7231 Information searching on the internet
7239 Other specified information by computing
7240 Unspecified communication by computer
7241 Communication on the internet
7249 Other specified communication by computing
7250 Unspecified other computing
7251 Skype or other video call
7259 Other specified computing
7300 Unspecified games
7310 Solo games and play
7320 Unspecified games and play with others
7321 Billiards pool snooker or petanque
7322 Chess and bridge
7329 Other specified parlour games and play
7330 Computer games
7340 Gambling
7390 Other specified games
8000 Unspecified mass media
8100 Unspecified reading
8110 Reading periodicals
8120 Reading books
8190 Other specified reading
8210 Unspecified TV video or DVD watching
8211 Watching a film on TV
8212 Watching sport on TV
8219 Other specified TV watching
8220 Unspecified video watching
8221 Watching a film on video
8222 Watching sport on video
8229 Other specified video watching
8300 Unspecified listening to radio and music
8310 Unspecified radio listening
8311 Listening to music on the radio
8312 Listening to sport on the radio
8319 Other specified radio listening
8320 Listening to recordings
9000 Travel related to unspecified time use
9010 Travel related to personal business
9100 Travel to/from work
9110 Travel in the course of work
9120 Travel to work from home and back only
9130 Travel to work from a place other than home
9210 Travel related to education
9230 Travel escorting to/ from education
9310 Travel related to household care
9360 Travel related to shopping
9370 Travel related to services
9380 Travel escorting a child other than education
9390 Travel escorting an adult other than education
9400 Travel related to organisational work
9410 Travel related to voluntary work and meetings
9420 Travel related to informal help to other households
9430 Travel related to religious activities
9440 Travel related to participatory activities other than religious activities
9500 Travel to visit friends/relatives in their homes not respondents household
9510 Travel related to other social activities
9520 Travel related to entertainment and culture
9600 Travel related to other leisure
9610 Travel related to physical exercise
9620 Travel related to hunting & fishing
9630 Travel related to productive exercise other than hunting & fishing
9710 Travel related to gambling
9720 Travel related to hobbies other than gambling
9800 Travel related to changing locality
9810 Travel to holiday base
9820 Travel for day trip/just walk
9890 Other specified travel
9940 Punctuating activity
9941 Unknown: at home
9950 Filling in the time use diary
9960 No main activity no idea what it might be
9970 No main activity some idea what it might be
9980 Illegible activity
9990 Unspecified time use
9999 Queryable
I created a matrix in R with 129 columns and 16533 rows.
Activities <-uktus15_diary_wide[,c ("serial", "pnum","ddayw","DVAge", "dmonth", "dyear","WhenDiary","AfterDiaryDay","WhereStart","WhereEnd","RushedD","Ordinary","KindOfDay","Trip","enjm1","act1_1, "act1_2", "act1_3", "act1_4", "act1_5", "act1_6", "act1_7", "act1_8", "act1_9", "act1_10", "act1_11", "act1_12", "act1_13", "act1_14","act1_15", "act1_16", "act1_17", "act1_18", "act1_19", " "act1_21", "act1_22", "act1_23", "act1_24", "act1_25", "act1_26", "act1_27", "act1_28", "act1_29", "act1_30",
"act1_31", "act1_32", "act1_33", "act1_34", "act1_35", "act1_36", "act1_37", "act1_38", "act1_39", "act1_40",
"act1_41", "act1_42", "act1_43", "act1_44", "act1_45", "act1_46", "act1_47", "act1_48", "act1_49", "act1_50",
"act1_51", "act1_52", "act1_53", "act1_54", "act1_55", "act1_56", "act1_57", "act1_58", "act1_59", "act1_60",
"act1_61", "act1_62", "act1_63", "act1_64", "act1_65", "act1_66", "act1_67", "act1_68", "act1_69", "act1_70",
"act1_71", "act1_72", "act1_73", "act1_74", "act1_75", "act1_76", "act1_77", "act1_78", "act1_79", "act1_80",
"act1_81", "act1_82", "act1_83", "act1_84", "act1_85", "act1_86", "act1_87", "act1_88", "act1_89", "act1_90",
"act1_91", "act1_92", "act1_93", "act1_94", "act1_95", "act1_96", "act1_97", "act1_98", "act1_99", "act1_100",
"act1_101", "act1_102", "act1_103", "act1_104", "act1_105", "act1_106", "act1_107", "act1_108", "act1_109",
"act1_110", "act1_111", "act1_112", "act1_113", "act1_114")]
Example how the data looks like (I included just serial pnum act1_28 (activity between 8:30-8:40), act1_29 (activity between 8:40-8:50 and act1_30 (activity between 8:50-0:90 variables)
serial pnum act1_28 act1_29 act1_30
11011202 1 3110 3110 3110
11011202 2 3310 3310 7241
11011202 4 9210 9210 9210
My question is can we use TraMineR in this case to mine sequences? Can act1_1, act1_2...act1_144 be defined as a sequence? Can activity codes be used to define states?
Here is how you create the state sequence object from your example data
library(TraMineR)
dat <- matrix(c(11011202, 1, 3110, 3110, 3110,
11011202, 2, 3310, 3310, 7241,
11011202, 4, 9210, 9210, 9210),
nrow=3, ncol=5, byrow=TRUE)
names(dat) <- c("serial", "pnum", "act1_28", "act1_29", "act1_30")
## creating the state sequence object
s <- seqdef(dat[,3:5])
seqiplot(s)
Here, only four different states are involved.
However, the alphabet for your whole dataset is much larger. Several features of TraMineR will either not work or not produce useful outcomes when the alphabet contains too many states. E.g., chronograms or index plots with so many different states would be unreadable. Moreover, TraMineR automatically assigns colors to states only as long as the size of the alphabet does not exceed 12. Of course, many functions such as computing the complexity of the individual sequences (seqici), the sequence of cross-sectional distributions at the successive time intervals and their entropies (seqstatd), or even computing pairwise dissimilarities (seqdist) should work with large alphabets.
Nevertheless, to use TraMineR, I would strongly recommend that you consider to recoding your states so as to drastically reduce your alphabet to say less than 20 different states.

How to get a brief description about a topic from wiki api?

I need to display a brief description about some topic. Like, when we search "India" on Google, it will show a brief description about India on the right side of the page, but that content is not an actual paragraph from wikipedia. does we get this content from wiki api?
https://www.mediawiki.org/wiki/Extension:TextExtracts#API, for example:
https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exintro=1&explaintext=1&titles=India&continue=&format=json&formatversion=2 outputs
{
"batchcomplete": true,
"query": {
"pages": [
{
"pageid": 14533,
"ns": 0,
"title": "India",
"extract": "India (/ˈɪndiə/), officially the Republic of India (Bhārat Gaṇarājya), is a country in South Asia. It is the seventh-largest country by area, the second-most populous country with over 1.2 billion people, and the most populous democracy in the world. Bounded by the Indian Ocean on the south, the Arabian Sea on the south-west, and the Bay of Bengal on the south-east, it shares land borders with Pakistan to the west; China, Nepal, and Bhutan to the north-east; and Burma (Myanmar) and Bangladesh to the east. In the Indian Ocean, India is in the vicinity of Sri Lanka and the Maldives; in addition, India's Andaman and Nicobar Islands share a maritime border with Thailand and Indonesia.\nHome to the ancient Indus Valley Civilisation and a region of historic trade routes and vast empires, the Indian subcontinent was identified with its commercial and cultural wealth for much of its long history. Four religions—Hinduism, Buddhism, Jainism, and Sikhism—originated here, whereas Zoroastrianism and the Abrahamic religions of Judaism, Christianity, and Islam arrived in the 1st millennium CE and also helped shape the region's diverse culture. Gradually annexed by and brought under the administration of the British East India Company from the early 18th century and administered directly by the United Kingdom after the Indian Rebellion of 1857, India became an independent nation in 1947 after a struggle for independence that was marked by non-violent resistance led by Mahatma Gandhi.\nThe Indian economy is the world's seventh-largest by nominal GDP and third-largest by purchasing power parity (PPP). Following market-based economic reforms in 1991, India became one of the fastest-growing major economies; it is considered a newly industrialised country. However, it continues to face the challenges of poverty, corruption, malnutrition, inadequate public healthcare, and terrorism. A nuclear weapons state and a regional power, it has the third-largest standing army in the world and ranks ninth in military expenditure among nations. India is a federal constitutional republic governed under a parliamentary system consisting of 29 states and 7 union territories. India is a pluralistic, multilingual, and a multi-ethnic society. It is also home to a diversity of wildlife in a variety of protected habitats."
}
]
}
}

use "Google Wallet for Digital Goods API " in TAIWAN?

Now I've to sign up for Google Wallet for Digital Goods (sandbox) ,
I want to set up a online billing for customer by using the Google wallet.
But when I entry this page
https://sandbox.google.com/checkout/inapp/merchant/signup.html
I can't find the "Taiwan" at "Country/Region" ,
Does it means that Taiwan can't use this service ?
At this time Google Wallet for Digital Goods is not available for Taiwan merchants. The link below has a list of eligible countries:
https://developers.google.com/wallet/digital/faq#faq-gen-02
Australia
Austria
Belgium
Canada
Denmark
Finland
France
Germany
Ireland
Italy
Japan
The Netherlands
Norway
Portugal
Spain
Sweden
United Kingdom
United States