Changing dictionary key to a float (Python) - python

I have a super long given dictionary like this:
book_dictionary = {'Fiction': [{'title': "Antiques Roadkill: A Trash 'n' Treasures Mystery", 'author': 'Barbara Allan', 'rating': '3.3', 'publisher': 'Kensington Publishing Corp.', 'page_count': '288', 'language': 'English'}, {'title': 'The Painted Man (The Demon Cycle, Book 1)', 'author': 'Peter V. Brett', 'rating': '4.5', 'publisher': 'HarperCollins UK', 'page_count': '544', 'language': 'English'}, {'title': 'Edgedancer: From the Stormlight Archive', 'author': 'Brandon Sanderson', 'rating': '4.8', 'publisher': 'Tor Books', 'page_count': '226', 'language': 'English'}, {'title': 'Sword of Destiny: Witcher 2: Tales of the Witcher', 'author': 'Andrzej Sapkowski', 'rating': '4.8', 'publisher': 'Hachette UK', 'page_count': '400', 'language': 'English'}, {'title': 'After Anna', 'author': 'Alex Lake', 'rating': '4.1', 'publisher': 'HarperCollins UK', 'page_count': '416', 'language': 'English'}, {'title': 'Little Girl Lost: A Lucy Black Thriller', 'author': 'Brian McGilloway', 'rating': '4', 'publisher': 'Harper Collins', 'page_count': '336', 'language': 'English'}, {'title': 'The Guardians: The explosive new thriller from international bestseller John Grisham', 'author': 'John Grisham', 'rating': '', 'publisher': 'Hachette UK', 'page_count': '384', 'language': 'English'}, {'title': 'Bring Me Back', 'author': 'B A Paris', 'rating': '3.8', 'publisher': 'HarperCollins UK', 'page_count': '368', 'language': 'English'}, {'title': "Final Option: 'The best one yet'", 'author': 'Clive Cussler', 'rating': '5', 'publisher': 'Penguin UK', 'page_count': '400', 'language': 'English'}, {'title': 'The Red Signal: An Agatha Christie Short Story', 'author': 'Agatha Christie', 'rating': '5', 'publisher': 'HarperCollins UK', 'page_count': '40', 'language': 'English'}, {'title': 'The Name of the Wind: The Kingkiller Chronicle:, Book 1', 'author': 'Patrick Rothfuss', 'rating': '4.3', 'publisher': 'Hachette UK', 'page_count': '672', 'language': 'English'}, {'title': 'Antiques Con', 'author': 'Barbara Allan', 'rating': '4.8', 'publisher': 'Kensington Books', 'page_count': '288', 'language': 'English'}, {'title': 'Antiques Chop', 'author': 'Barbara Allan', 'rating': '4.5', 'publisher': 'Kensington Books', 'page_count': '240', 'language': 'English'}, {'title': "Salem's Lot", 'author': 'Stephen King', 'rating': '4.4', 'publisher': 'Hachette UK', 'page_count': '300', 'language': 'English'}, {'title': 'Killer Blonde', 'author': 'Laura Levine', 'rating': '4', 'publisher': 'Kensington Books', 'page_count': '288', 'language': 'English'}, {'title': 'No Mercy: The brand new novel from the Queen of Crime', 'author': 'Martina Cole', 'rating': '', 'publisher': 'Hachette UK', 'page_count': '416', 'language': 'English'}, {'title': 'Antiques Knock-Off', 'author': 'Barbara Allan', 'rating': '4.3', 'publisher': 'Kensington Publishing Corp.', 'page_count': '240', 'language': 'English'}, {'title': 'A Trace of Vice (a Keri Locke Mystery--Book #3)', 'author': 'Blake Pierce', 'rating': '4.8', 'publisher': 'Blake Pierce', 'page_count': '250', 'language': 'English'}, {'title': 'Total Control', 'author': 'David Baldacci', 'rating': '4', 'publisher': 'Pan Macmillan', 'page_count': '624', 'language': 'English'}, {'title': 'Mrs. Pollifax Unveiled', 'author': 'Dorothy Gilman', 'rating': '3.9', 'publisher': 'Ballantine Books', 'page_count': '208', 'language': 'English'}, {'title': 'And Then There Were None', 'author': 'Agatha Christie', 'rating': '4.6', 'publisher': 'HarperCollins UK', 'page_count': '224', 'language': 'English'}, {'title': 'The Lord of the Rings: The Fellowship of the Ring, The Two Towers, The Return of the King', 'author': 'J. R. R. Tolkien', 'rating': '4.6', 'publisher': 'HarperCollins UK', 'page_count': '1216', 'language': 'English'}, {'title': 'A Feast for Crows (A Song of Ice and Fire, Book 4)', 'author': 'George R.R. Martin', 'rating': '4.5', 'publisher': 'HarperCollins UK', 'page_count': '864', 'language': 'English'}, {'title': 'A Game of Thrones: The Story Continues Books 1-5: A Game of Thrones, A Clash of Kings, A Storm of Swords, A Feast for Crows, A Dance with Dragons (A Song of Ice and Fire)', 'author': 'George R.R. Martin', 'rating': '4.5', 'publisher': 'HarperCollins UK', 'page_count': '4544', 'language': 'English'}, {'title': 'The Mysterious Affair at Styles', 'author': 'Agatha Christie', 'rating': '4.4', 'publisher': 'HarperCollins UK', 'page_count': '208', 'language': 'English'}, {'title': "The Girl in the Spider's Web: A Lisbeth Salander novel, continuing Stieg Larsson's Millennium Series", 'author': 'David Lagercrantz', 'rating': '4.1', 'publisher': 'Vintage Crime/Black Lizard', 'page_count': '416', 'language': 'English'}, {'title': 'Night of the Bold (Kings and Sorcerers--Book 6)', 'author': 'Morgan Rice', 'rating': '4.3', 'publisher': 'Morgan Rice', 'page_count': '250', 'language': 'English'}, {'title': 'A Trace of Crime (a Keri Locke Mystery--Book #4)', 'author': 'Blake Pierce', 'rating': '4.7', 'publisher': 'Blake Pierce', 'page_count': '250', 'language': 'English'}, {'title': 'Shantaram', 'author': 'Gregory David Roberts', 'rating': '4.5', 'publisher': 'Hachette UK', 'page_count': '944', 'language': 'English'}, {'title': 'The Black Box', 'author': 'Michael Connelly', 'rating': '4', 'publisher': 'Hachette UK', 'page_count': '448', 'language': 'English'}, {'title': 'The Tower of the Swallow: Witcher 6', 'author': 'Andrzej Sapkowski', 'rating': '4.6', 'publisher': 'Hachette UK', 'page_count': '400', 'language': 'English'}, {'title': 'Prince of Thorns (The Broken Empire, Book 1)', 'author': 'Mark Lawrence', 'rating': '4.2', 'publisher': 'HarperCollins UK', 'page_count': '416', 'language': 'English'}, {'title': 'The Vagrant (The Vagrant Trilogy)', 'author': 'Peter Newman', 'rating': '4.2', 'publisher': 'HarperCollins UK', 'page_count': '416', 'language': 'English'}, {'title': 'The Weight of Honor (Kings and Sorcerers--Book 3)', 'author': 'Morgan Rice', 'rating': '4.4', 'publisher': 'Morgan Rice', 'page_count': '250', 'language': 'English'}, {'title': 'The Memoirs of Sherlock Holmes', 'author': 'Arthur Conan Doyle', 'rating': '4.2', 'publisher': 'Simon and Schuster', 'page_count': '320', 'language': 'English'}, {'title': 'We', 'author': 'Yevgeny Zamyatin', 'rating': '4.3', 'publisher': 'Pan', 'page_count': '226', 'language': 'English'}, {'title': 'In Dark Company: A Kate Burkholder Short Story', 'author': 'Linda Castillo', 'rating': '4.3', 'publisher': 'Minotaur Books', 'page_count': '60', 'language': 'English'}, {'title': "Chronicle of the Unhewn Throne: (The Emperor's Blades, The Providence of Fire, The Last Mortal Bond)", 'author': 'Brian Staveley', 'rating': '4.3', 'publisher': 'Macmillan', 'page_count': '1728', 'language': 'English'}, {'title': 'The Malady and Other Stories: An Andrzej Sapkowski Sampler', 'author': 'Andrzej Sapkowski', 'rating': '4.8', 'publisher': 'Hachette UK', 'page_count': '96', 'language': 'English'}], 'Comics': [{'title': 'Deadpool Kills the Marvel Universe', 'author': 'Cullen Bunn', 'rating': '4.2', 'publisher': 'Marvel Entertainment', 'page_count': '96', 'language': 'English'}, {'title': 'Young Justice Vol. 1', 'author': 'Art Baltazar', 'rating': '4.1', 'publisher': 'DC', 'page_count': '164', 'language': 'English'}, {'title': 'Ultimate Spider-Man Vol. 11: Carnage', 'author': 'Brian Michael Bendis', 'rating': '4.1', 'publisher': 'Marvel Entertainment', 'page_count': '144', 'language': 'English'}, {'title': 'Immortal Hulk Vol. 1: Or Is He Both?', 'author': 'Al Ewing', 'rating': '4.4', 'publisher': 'Marvel Entertainment', 'page_count': '128', 'language': 'English'}, {'title': 'Watchmen (2019 Edition)', 'author': 'Alan Moore', 'rating': '4.2', 'publisher': 'DC Comics', 'page_count': '448', 'language': 'English'}, {'title': 'The Joker', 'author': 'Brian Azzarello', 'rating': '4.4', 'publisher': 'DC', 'page_count': '130', 'language': 'English'}, {'title': 'Venomized', 'author': 'Cullen Bunn', 'rating': '4.5', 'publisher': 'Marvel Entertainment', 'page_count': '136', 'language': 'English'}], {'Economics':[...]}}
NOTE: There are empty ratings.
What I am trying to do is write a function that takes an integer argument, the rating, and the dictionary itself. The function returns a list with the book for the given rating.
For example, if the input parameter of the function is 3, the function will return the book whose rate is greater or equal to 3 and smaller than 4. It will then print it like:
Title: "Antiques Roadkill: A Trash 'n' Treasures Mystery"
Authors: " Barbara Allan”
Language: "English"
Rating: 3.3
Publisher: "Kensington Publishing Corp."
Category: "Fiction”
Page Count: 288
What I currently have is:
def get_books_by_rate(rate: int, book_dictionary) -> list:
ratings = []
for category in book_dictionary.keys():
books = book_dictionary[category]
for book in books:
x = book['rating']
if (x >= rate) and (x < rate + 1):
title = book('title')
author = book('author')
language = book('language')
rating = book('rating')
publisher = book('publisher')
cat = books
page_count = book('page_count')
result = {'Title': title,
'Authors': author,
'Language': language,
'Rating': rating,
'Publisher': publisher,
'Category': cat,
'Page Count': page_count}
ratings.append(result)
return ratings
get_books_by_rate_print = get_books_by_rate(3, book_dictionary)
print(get_books_by_rate_print)
I am trying to get the function to properly print before attempting to format it. However, I am stuck:
Traceback (most recent call last):
File "C:/Users/aL/Downloads/Python/rate_func.py", line 50, in <module>
get_books_by_rate_print = get_books_by_rate(3, book_dictionary)
File "C:/Users/aL/Downloads/Python/rate_func.py", line 31, in <module>
if (x >= rate) and (x < rate + 1):
builtins.TypeError: '>=' not supported between instances of 'str' and 'int'
I am not sure how to convert x into a float/int value to compare the two variables.

Try this:
def get_books_by_rate(rate: int, book_dictionary) -> list:
ratings = []
for category in book_dictionary.keys():
books = book_dictionary[category]
for book in books:
x = 0
rating_valid = True
try:
x = float(book['rating'])
except:
rating_valid = False
if rating_valid and (x >= rate) and (x < rate + 1):
result = {}
result.update({'Title': book['title']})
result.update({'Authors': book['author']})
result.update({'Language': book['language']})
result.update({'Rating': book['rating']})
result.update({'Publisher': book['publisher']})
result.update({'Category': category})
result.update({'Page Count': book['page_count']})
ratings.append(result)
return ratings
book_dictionary = *PUT YOUR DICTIONARY HERE*
get_books_by_rate_print = get_books_by_rate(3, book_dictionary)
for item in get_books_by_rate_print:
print(item)

This approach should work as well:
my_dict = {'Fiction': [{'title': "Antiques Roadkill: A Trash 'n' Treasures Mystery", 'author': 'Barbara Allan', 'rating': '3.3', 'publisher': 'Kensington Publishing Corp.', 'page_count': '288', 'language': 'English'}],
'Economics': [{'title': 'How To Win Friends and Influence People', 'author': 'Dale Carnegie', 'rating': '4.3', 'publisher': 'Simon and Schuster', 'page_count': '320', 'language': 'English'}]}
def get_books_by_rate(rate: int, book_dictionary = my_dict) -> list:
res = []
vote = int(rate)
for k, l in book_dictionary.items():
for book in l:
if vote == int(float(book["rating"])):
book["category"] = k
res.append(book)
return res
def print_book(book):
print(f'Title: {book["title"]}')
print(f'Authors: {book["author"]}')
print(f'Language: {book["language"]}')
print(f'Rating: {book["rating"]}')
print(f'Publisher: {book["publisher"]}')
print(f'Category: {book["category"]}')
print(f'Page Count: {book["page_count"]}')
for book in get_books_by_rate(3):
print_book(book)
print(30 * "-")
I think truncating the float rating to its integer part using int(float(book["rating"])) is more compact that something like min <= rating < max, but maybe it is just matter of tastes.

Perhaps this will help:
book_dictionary = {'Fiction': [{'title': "Antiques Roadkill: A Trash 'n' Treasures Mystery", 'author': 'Barbara Allan', 'rating': '3.3', 'publisher': 'Kensington Publishing Corp.', 'page_count': '288', 'language': 'English'}],
'Economics': [{'title': 'How To Win Friends and Influence People', 'author': 'Dale Carnegie', 'rating': '4.3', 'publisher': 'Simon and Schuster', 'page_count': '320', 'language': 'English'}]}
def get_books_by_rate(rate, books):
ratings = []
for v in books.values():
for lb in v:
rating = float(lb['rating'])
if rating >= rate and rating < rate + 1:
ratings.append(lb)
return ratings
print(get_books_by_rate(3, book_dictionary))

Use .strip() to remove space, and float() to convert type to float.
To set empty rating as 0:
rating = book['rating'].strip()
x = float(rating) if rating != '' else 0
or, to ignore empty ratings:
rating = book['rating'].strip()
if rating == '':
continue

Related

How to sort lists of dictionaries according to values of ONE key type? [duplicate]

This question already has answers here:
How do I sort a list of dictionaries by a value of the dictionary?
(20 answers)
Closed 11 months ago.
I have the following list of dictionaries:
[{'title': 'Shrek the Musical', 'year': 2013, 'genres': ['Comedy', 'Family', 'Fantasy'], 'duration': 130, 'directors': ['Michael John Warren'], 'actors': ["Brian d'Arcy James", 'Sutton Foster', 'Christopher Sieber'], 'rating': 7.0},
{'title': 'Shrek Retold', 'year': 2018, 'genres': ['Animation', 'Adventure', 'Comedy'], 'duration': 90, 'directors': ['Grant Duffrin'], 'actors': ['Harry Antonucci', 'Russell Bailey'], 'rating': 7.5},
{'title': 'Shrek 2', 'year': 2004, 'genres': ['Animation', 'Adventure', 'Comedy'], 'duration': 93, 'directors': ['Andrew Adamson', 'Kelly Asbury'], 'actors': ['Mike Myers', 'Eddie Murphy'], 'rating': 7.2},
{'title': 'Shrek the Third', 'year': 2007, 'genres': ['Animation', 'Adventure', 'Comedy'], 'duration': 93, 'directors': ['Chris Miller', 'Raman Hui'], 'actors': ['Mike Myers', 'Eddie Murphy', 'Cameron Diaz', 'Antonio Banderas'], 'rating': 6.1},
{'title': 'Shrek Forever After', 'year': 2010, 'genres': ['Animation', 'Adventure', 'Comedy'], 'duration': 93, 'directors': ['Mike Mitchell'], 'actors': ['Mike Myers', 'Eddie Murphy', 'Cameron Diaz', 'Antonio Banderas'], 'rating': 6.3},
{'title': 'Shrek', 'year': 2001, 'genres': ['Animation', 'Adventure', 'Comedy'], 'duration': 90, 'directors': ['Andrew Adamson', 'Vicky Jenson'], 'actors': ['Mike Myers', 'Eddie Murphy'], 'rating': 7.8}]
I want to produce a list of movies sorted in increasing order of their year of release. That is, the sorting should just depend on one value, ignoring all other keys.
I tried using the sorted function, but I don't know how to specify that the dictionaries should be sorted based on a single value.
You can pass a key parameter to sorted() to tell it which key to sort on:
result = sorted(data, key=lambda x: x['year'])
print(result)
This outputs:
[{'title': 'Shrek', 'year': 2001, 'genres': ['Animation', 'Adventure', 'Comedy'], 'duration': 90, 'directors': ['Andrew Adamson', 'Vicky Jenson'], 'actors': ['Mike Myers', 'Eddie Murphy'], 'rating': 7.8},
{'title': 'Shrek 2', 'year': 2004, 'genres': ['Animation', 'Adventure', 'Comedy'], 'duration': 93, 'directors': ['Andrew Adamson', 'Kelly Asbury'], 'actors': ['Mike Myers', 'Eddie Murphy'], 'rating': 7.2},
{'title': 'Shrek the Third', 'year': 2007, 'genres': ['Animation', 'Adventure', 'Comedy'], 'duration': 93, 'directors': ['Chris Miller', 'Raman Hui'], 'actors': ['Mike Myers', 'Eddie Murphy', 'Cameron Diaz', 'Antonio Banderas'], 'rating': 6.1},
{'title': 'Shrek Forever After', 'year': 2010, 'genres': ['Animation', 'Adventure', 'Comedy'], 'duration': 93, 'directors': ['Mike Mitchell'], 'actors': ['Mike Myers', 'Eddie Murphy', 'Cameron Diaz', 'Antonio Banderas'], 'rating': 6.3},
{'title': 'Shrek the Musical', 'year': 2013, 'genres': ['Comedy', 'Family', 'Fantasy'], 'duration': 130, 'directors': ['Michael John Warren'], 'actors': ["Brian d'Arcy James", 'Sutton Foster', 'Christopher Sieber'], 'rating': 7.0},
{'title': 'Shrek Retold', 'year': 2018, 'genres': ['Animation', 'Adventure', 'Comedy'], 'duration': 90, 'directors': ['Grant Duffrin'], 'actors': ['Harry Antonucci', 'Russell Bailey'], 'rating': 7.5}]

Convert JSON data to pandas df - python

I know there is a few questions on SO regarding the conversion of JSON file to a pandas df but nothing is working. Specifically, the JSON requests the current days information. I'm trying to return the tabular structure that corresponds with Data but I'm only getting the first dict object.
I'll list the current attempts and the resulting outputs below.
import requests
import pandas as pd
import json
get_session_url = "https://qships.tmr.qld.gov.au/webx/"
get_data_url = "https://qships.tmr.qld.gov.au/webx/services/wxdata.svc/GetDataX"
get_data_query = {
"token": None,
"reportCode": "MSQ-WEB-0001",
"dataSource": None,
"filterName": "Today",
"parameters": [{
"__type": "ParameterValueDTO:#WebX.Core.DTO",
"sName": "DOMAIN_ID",
"iValueType": 0,
"aoValues": [{"Value": -1}],
}],
"metaVersion": 0,
}
sess = requests.session()
sess.get(get_session_url).raise_for_status()
my_dict = sess.post(get_data_url, json = get_data_query).json()
print(my_dict)
Output:
{'d': {'__type': 'DataSetDTO:#WebX.Core.DTO', 'BuildVersion': '7.0.0.12590', 'ReportCode': 'MSQ-WEB-0001', 'Tables': [{'__type': 'DataTableDTO:#WebX.Core.DTO', 'BuildVersion': '7.0.0.12590', 'AsOfDate': '14:36 on Jan 19', 'Data': [[132378, 334489, 'EXT', 'NANA Z', 'BULK CARRIER', 229.2, 'LBH Australia Pty Ltd (Mackay)', '/Date(1642600800000+1000)/', '/Date(1642600800000+1000)/', 'SEA for HPS', 'Anch for HPS & DBCT', 'PLAN', 'Keelung (Chilung)', 'Kwangyang', None, 633086, 705], [132112, 333984, 'DEP', 'KRITI WARRIOR', 'BULK CARRIER', 234.98, 'Wilhelmsen Ships Service (Gladstone)', '/Date(1642600800000+1000)/', '/Date(1642608900000+1000)/', 'Fishermans Landing 1', 'SEA', 'CONF', 'Amrun', 'Amrun', '2201', 632395, 725], [132232, 334208, 'EXT', 'BLUE GRASS MARINER', 'TANKER', 183.06, 'Gulf Agency Company (Mackay)', '/Date(1642600860000+1000)/', '/Date(1642600860000+1000)/', 'SEA M', 'Anch for MKY', 'PLAN', 'Gladstone', 'Singapore', None, 633566, 705], [132654, 335076, 'EXT', 'SERIFOS WARRIOR', 'BULK CARRIER', 234.98, 'Wilhelmsen Ships Service (Gladstone)', '/Date(1642606200000+1000)/', '/Date(1642609800000+1000)/', 'SEA', 'Fairway Buoy Anchorage', 'PLAN', 'Amrun', 'Amrun', '2201', 632055, 705], [132030, 333847, 'ARR', 'MH GREEN', 'CONTAINER SHIP', 199.98, 'Inchcape Shipping Services (Queensland)', '/Date(1642610700000+1000)/', '/Date(1642623300000+1000)/', 'SEA', 'Fisherman Island No 8', 'SCHD', 'Yantian', 'Botany Bay', '11S/11N', 633005, 710], [131681, 333193, 'ARR', 'KM NAGOYA', 'BULK CARRIER', 234.98, 'Gulf Agency Company (Gladstone)', '/Date(1642611600000+1000)/', '/Date(1642618800000+1000)/', 'Fairway Buoy Anchorage', 'Clinton Coal 2', 'CONF', 'Fangcheng', 'Singapore', None, 633504, 725], [132781, 335341, 'ARR', 'MORNING CLARA', 'VEHICLES CARRIER', 199.9, 'Wilhelmsen Ships Service (Brisbane)', '/Date(1642611600000+1000)/', '/Date(1642626000000+1000)/', 'Drift Point Cartwright', 'Fisherman Island No 1', 'SCHD', 'Tianjin', 'Port Kembla', '2251', 633093, 710], [131971, 333736, 'DEP', 'MAPLE FORTITUDE', 'BULK CARRIER', 179.9, 'Inchcape Shipping Services (Queensland)', '/Date(1642615200000+1000)/', '/Date(1642621500000+1000)/', 'Townsville 09', 'SEA', 'SCHD', 'Lanshan', 'Auckland', '2101', 633738, 710], [131629, 333076, 'DEP', 'JP CORAL', 'BULK CARRIER', 228.0, 'Sturrock Grindrod Maritime (Gladstone)', '/Date(1642617000000+1000)/', '/Date(1642625100000+1000)/', 'Clinton Coal 2', 'SEA', 'CONF', 'Matsushima - Nagasaki', 'Matsuura - Nagasaki', '146', 631305, 725], [130504, 331071, 'ARR', 'KENNADI', 'BULK CARRIER', 199.9, 'LBH Australia Pty Ltd (Gladstone)', '/Date(1642617000000+1000)/', '/Date(1642626000000+1000)/', 'East Anchorage 9', 'Clinton Coal 4', 'CONF', 'Kwangyang', 'Kendari - Sulawesi', '37', 633759, 725], [131497, 332926, 'ARR', 'STAR VIRGINIA', 'BULK CARRIER', 229.0, 'Inchcape Shipping Services (Queensland)', '/Date(1642617900000+1000)/', '/Date(1642633200000+1000)/', 'Point Cartwright Anchorage', 'Fisherman Island Coal Berth', 'SCHD', 'Kitakyushu', 'Fukuyama - Hiroshima', '2', 632115, 710], [132459, 334657, 'ARR', 'NORD ANNAPOLIS', 'BULK CARRIER', 179.9, 'Monson Agencies Australia (Gladstone)', '/Date(1642617900000+1000)/', '/Date(1642625100000+1000)/', 'East Anchorage 11', 'Auckland Point 2', 'CONF', 'Portland', 'Chittagong', '26', 633752, 725], [132563, 334863, 'DEP', 'POSITIVE LEADER', 'VEHICLES CARRIER', 180.0, 'Monson Agencies Australia (Brisbane)', '/Date(1642622400000+1000)/', '/Date(1642635000000+1000)/', 'Fisherman Island No 1', 'SEA', 'SCHD', 'Townsville', 'Port Kembla', '090', 632525, 710], [132221, 334613, 'ARR', 'DANCEWOOD SW', 'BULK CARRIER', 170.7, 'Inchcape Shipping Services (Queensland)', '/Date(1642622400000+1000)/', '/Date(1642640400000+1000)/', 'Point Cartwright Anchorage', 'Pinkenba No 1', 'SCHD', 'Guam', 'Shibushi', '202201', 632332, 710], [132357, 334450, 'EXT', 'DOUBLE FANTASY', 'BULK CARRIER', 234.98, 'Monson Agencies Australia (Townsville & Abbot Point)', '/Date(1642622400000+1000)/', '/Date(1642622400000+1000)/', 'SEA', 'Abbot Point Anchorage', 'SCHD', 'Chiba', None, None, 631611, 710], [132431, 334598, 'DEP', 'INDUS PROSPERITY', 'BULK CARRIER', 229.2, 'Monson Agencies Australia (Townsville & Abbot Point)', '/Date(1642624200000+1000)/', '/Date(1642624200000+1000)/', 'Abott Point 2', 'SEA', 'SCHD', 'Chiba', 'Dung Quat', None, 627891, 710], [132465, 334672, 'DEP', 'KOTA LUMAYAN', 'CONTAINER SHIP', 260.502, 'Gulf Agency Company (Brisbane)', '/Date(1642626000000+1000)/', '/Date(1642639500000+1000)/', 'Fisherman Island No. 9', 'SEA', 'PLAN', 'Singapore', 'Sydney', '0147', 632026, 705], [132356, 334446, 'ARR', 'TRITON', 'BULK CARRIER', 225.0, 'Sturrock Grindrod Maritime (Mackay)', '/Date(1642626000000+1000)/', '/Date(1642632000000+1000)/', 'North Anchorage 22', 'HPS Berth 2', 'SCHD', 'Gunsan (ex Kunsan)', 'Singapore', '012022', 633638, 710], [132430, 334595, 'ARR', 'GOLDEN YOSA', 'TANKER', 144.03, 'Sturrock Grindrod Maritime (Brisbane)', '/Date(1642626000000+1000)/', '/Date(1642644000000+1000)/', 'SEA', 'Viva Energy', 'SCHD', 'Geelong', 'Townsville', '74(C1)', 628015, 710], [132631, 335048, 'DEP', 'MONDIAL SUN', 'BULK CARRIER', 229.0, 'Ben Line Agencies', '/Date(1642626000000+1000)/', '/Date(1642629600000+1000)/', 'Abbot Point 1', 'SEA', 'SCHD', 'Bahudopi', 'India', '018', 633700, 710], [132451, 334640, 'EXT', 'GOLDEN HACHI', 'TANKER', 126.8, 'Sturrock Grindrod Maritime (Brisbane)', '/Date(1642626000000+1000)/', '/Date(1642626000000+1000)/', 'SEA', 'Point Cartwright Anchorage', 'PLAN', 'Singapore', 'Botany Bay', '10', 632483, 705], [132442, 334622, 'DEP', 'FOREVER SW', 'BULK CARRIER', 189.99, 'Gulf Agency Company (Brisbane)', '/Date(1642626000000+1000)/', '/Date(1642643100000+1000)/', 'Fisherman Island Coal Berth', 'SEA', 'SCHD', 'Toledo/Cebu', 'Kushiro', '2A', 569051, 710], [132572, 334905, 'ARR', 'GREEK FRIENDSHIP', 'BULK CARRIER', 228.9, 'LBH Australia Pty Ltd (Mackay)', '/Date(1642627800000+1000)/', '/Date(1642627800000+1000)/', 'Abbot Point Anchorage 11', 'Abott Point 2', 'SCHD', 'Tianjin', 'Singapore', None, 633660, 710], [132262, 334259, 'DEP', 'ASTREA', 'BULK CARRIER', 228.99, 'Wave Shipping Pty Ltd', '/Date(1642627800000+1000)/', '/Date(1642627860000+1000)/', 'HPS Berth 1', 'SEA Paddock Departure', 'PLAN', 'Lianyungang', 'Singapore', '1', 633595, 705], [132510, 334762, 'DEP', 'BRILLIANT ADVANCE', 'BULK CARRIER', 228.99, 'Wilhelmsen Ships Service (Weipa)', '/Date(1642629600000+1000)/', '/Date(1642633200000+1000)/', 'Chith Export Facility', 'SEA', 'CONF', 'Laizhou', 'Gladstone', None, 631808, 725], [132170, 334112, 'ARR', 'LOWLANDS CRIMSON', 'BULK CARRIER', 234.96, 'Wilhelmsen Ships Service (Weipa)', '/Date(1642629600000+1000)/', '/Date(1642636800000+1000)/', 'Anchorage ^D', 'Chith Export Facility', 'CONF', 'Gladstone', 'China', None, 630787, 725], [132433, 334601, 'DEP', 'PT NORFOLK', 'GENERAL CARGO BARGE', 70.15, 'Pacific Tug (Aust) PTY LTD', '/Date(1642631400000+1000)/', '/Date(1642635000000+1000)/', 'Marina', 'Bundaberg Anchorage', 'CONF', None, None, None, 624749, 725], [132428, 334591, 'REM', 'PT KYTHIRA', 'TUG', 26.0, 'Pacific Tug (Aust) PTY LTD', '/Date(1642631400000+1000)/', '/Date(1642635000000+1000)/', 'Marina', 'Bundaberg Anchorage', 'CONF', None, 'Brisbane', None, 570086, 725], [131637, 333097, 'ARR', 'BALZANI', 'TANKER', 228.418, 'Monson Agencies Australia (Gladstone)', '/Date(1642632300000+1000)/', '/Date(1642642200000+1000)/', 'North Anchorage 7', 'Fishermans Landing 2', 'CONF', 'Yeosu (ex Yosu)', 'Port Kembla', '32106', 632359, 725], [132699, 335167, 'EXT', 'FEDERAL IMABARI', 'BULK CARRIER', 199.98, 'Monson Agencies Australia (Brisbane)', '/Date(1642633200000+1000)/', '/Date(1642633200000+1000)/', 'Skardon River Anchorage', 'SEA', 'CONF', None, None, None, 624678, 725], [132451, 335328, 'ARR', 'GOLDEN HACHI', 'TANKER', 126.8, 'Sturrock Grindrod Maritime (Brisbane)', '/Date(1642635000000+1000)/', '/Date(1642651200000+1000)/', 'Point Cartwright Anchorage', 'Ampol Lytton Products', 'PLAN', 'Singapore', 'Botany Bay', '10', 632483, 705], [131897, 333604, 'DEP', 'PROTEUS', 'TANKER', 183.06, 'Gulf Agency Company (Mackay)', '/Date(1642635000000+1000)/', '/Date(1642635060000+1000)/', 'Mackay Berth 1', 'SEA MKY', 'SCHD', 'Gladstone', 'Townsville', None, 633592, 710], [132059, 333886, 'ARR', 'RTM WAKMATHA', 'BULK CARRIER', 236.0, 'Wilhelmsen Ships Service (Gladstone)', '/Date(1642635000000+1000)/', '/Date(1642644900000+1000)/', 'Fairway Buoy Anchorage', 'Fishermans Landing 1', 'CONF', 'Gove', 'Amrun', None, 633057, 725], [132024, 333833, 'ARR', 'MARIA PRINCESS', 'TANKER', 228.59, 'Gulf Agency Company (Brisbane)', '/Date(1642635000000+1000)/', '/Date(1642654800000+1000)/', 'Point Cartwright Anchorage', 'Fishermans Island Tanker Terminal', 'SCHD', 'Seria Brunei', None, None, 633606, 710], [132504, 334740, 'EXT', 'MAIRAKI', 'BULK CARRIER', 291.9, 'LBH Australia Pty Ltd (Gladstone)', '/Date(1642636800000+1000)/', '/Date(1642636800000+1000)/', 'SEA', 'Drift Gladstone', 'PLAN', 'Tianjin', None, '43', 633705, 705], [132029, 333846, 'DEP', 'MANTA NILGUN', 'GENERAL CARGO', 179.99, 'Monson Agencies Australia (Gladstone)', '/Date(1642637700000+1000)/', '/Date(1642644000000+1000)/', 'South Trees East', 'SEA', 'CONF', 'Port Moresby', 'Nakhodka', '202201', 632946, 725], [132001, 333781, 'ARR', 'NSU KEYSTONE', 'BULK CARRIER', 299.94, 'Inchcape Shipping Services (Queensland)', '/Date(1642638600000+1000)/', '/Date(1642644000000+1000)/', 'North Anchorage 19', 'DBCT Berth 1', 'SCHD', 'Yeosu (ex Yosu)', 'Kimitsu', '57', 633532, 710], [131382, 332650, 'EXT', 'AQUADIVA', 'BULK CARRIER', 292.0, 'Gulf Agency Company (Gladstone)', '/Date(1642639500000+1000)/', '/Date(1642643100000+1000)/', 'SEA', 'Fairway Buoy Anchorage', 'PLAN', 'Bayuquan', 'Abbot Point', None, 633453, 705], [132417, 334562, 'DEP', 'KMARIN KENAI', 'BULK CARRIER', 229.0, 'Monson Agencies Australia (Mackay)', '/Date(1642640400000+1000)/', '/Date(1642644000000+1000)/', 'DBCT Berth 1', 'SEA Paddock Departure', 'SCHD', 'Yeosu (ex Yosu)', 'Sepetiba', None, 633645, 710], [132708, 335184, 'ARR', 'MSC ELA', 'CONTAINER SHIP', 294.06, 'Mediterranean Shipping Company', '/Date(1642641300000+1000)/', '/Date(1642654800000+1000)/', 'SEA', 'Fisherman Island No. 9', 'SCHD', 'Sydney', 'Shanghai', 'SE151R', 633718, 710], [132611, 335017, 'DEP', 'SSB 1803', 'BARGE CARRIER', 52.7, 'Sea Swift Pty Ltd', '/Date(1642644000000+1000)/', '/Date(1642647600000+1000)/', 'Hammond Island', 'SEA', 'CONF', None, None, None, 586569, 725], [132429, 334592, 'EXT', 'LEONORA VICTORY', 'TANKER', 183.2, 'Monson Agencies Australia (Gladstone)', '/Date(1642644000000+1000)/', '/Date(1642644000000+1000)/', 'SEA', 'Fairway Buoy Anchorage', 'PLAN', 'Balboa', 'Unknown Port', '32', 633737, 705], [132601, 335000, 'DEP', 'NORMAN RIVER', 'TUG', 24.45, 'Sea Swift Pty Ltd', '/Date(1642644000000+1000)/', '/Date(1642647600000+1000)/', 'Hammond Island', 'SEA', 'CONF', 'Cape Flattery', 'Cairns', None, 633691, 725], [132079, 335477, 'EXT', 'DEE4 LARCH', 'TANKER', 183.06, 'Inchcape Shipping Services (Queensland)', '/Date(1642646040000+1000)/', '/Date(1642646040000+1000)/', 'East Anchorage 6', 'SEA', 'PLAN', 'Etajima', 'Unknown Port', '1', 632184, 705], [132470, 334682, 'ARR', 'CASTILLO DE SANTISTEBAN', 'LIQUEFIED GAS TANKER', 299.9, 'Gulf Agency Company (Gladstone)', '/Date(1642646700000+1000)/', '/Date(1642658400000+1000)/', 'LNG Anchorage 2', 'Queensland Curtis LNG', 'CONF', 'Taiwan', 'Ningbo', None, 632133, 725], [132434, 334603, 'REM', 'PT NORFOLK', 'GENERAL CARGO BARGE', 70.15, 'Pacific Tug (Aust) PTY LTD', '/Date(1642647600000+1000)/', '/Date(1642662000000+1000)/', 'Shark Spit Anchorage', 'Queensport', 'SCHD', None, None, None, 624749, 710], [132538, 334816, 'EXT', 'WINCANTON', 'LIQUEFIED GAS TANKER', 119.95, 'Inchcape Shipping Services (Queensland)', '/Date(1642647600000+1000)/', '/Date(1642647600000+1000)/', 'SEA', 'Fairway Buoy Anchorage', 'PLAN', 'Newcastle', 'Newcastle', '264', 632386, 705], [132432, 334600, 'REM', 'PT KYTHIRA', 'TUG', 26.0, 'Pacific Tug (Aust) PTY LTD', '/Date(1642647600000+1000)/', '/Date(1642662000000+1000)/', 'Shark Spit Anchorage', 'Queensport', 'SCHD', 'Bundaberg', None, None, 570086, 710], [131727, 333300, 'ARR', 'SEMIRAMIS', 'BULK CARRIER', 228.9, 'Sturrock Grindrod Maritime (Mackay)', '/Date(1642647660000+1000)/', '/Date(1642653060000+1000)/', 'South Anchorage 09', 'HPS Berth 1', 'PLAN', 'Jingtang (Tangshan)', 'Singapore', 'TP0264', 633516, 705], [132130, 335179, 'ARR', 'CHORUS', 'BULK CARRIER', 228.99, 'Monson Agencies Australia (Mackay)', '/Date(1642649400000+1000)/', None, 'North Anchorage 06', 'DBCT Berth 3', 'SCHD', 'Busan', 'Kakogawa', '80', 633558, 710], [132439, 334614, 'EXT', 'SM TIGER', 'BULK CARRIER', 292.0, 'LBH Australia Pty Ltd (Mackay)', '/Date(1642649400000+1000)/', '/Date(1642649400000+1000)/', 'SEA for HPS', 'Anch for HPS & DBCT', 'PLAN', 'Kwangyang', 'Pohang', '50', 633640, 705], [132795, 335381, 'ARR', 'ALBATROSS BAY', 'LANDING CRAFT', 64.0, 'Sea Swift Pty Ltd', '/Date(1642651200000+1000)/', '/Date(1642654800000+1000)/', 'SEA', 'Horn Island', 'CONF', 'Cairns', 'Seisia', 'AB 2203', 633274, 725], [132433, 335356, 'ARR', 'PT NORFOLK', 'GENERAL CARGO BARGE', 70.15, 'Pacific Tug (Aust) PTY LTD', '/Date(1642651200000+1000)/', '/Date(1642654800000+1000)/', 'Bundaberg Anchorage', 'Marina', 'CONF', None, None, None, 624749, 725], [132428, 335355, 'REM', 'PT KYTHIRA', 'TUG', 26.0, 'Pacific Tug (Aust) PTY LTD', '/Date(1642651200000+1000)/', '/Date(1642654800000+1000)/', 'Bundaberg Anchorage', 'Marina', 'CONF', None, 'Brisbane', None, 570086, 725], [132295, 334319, 'DEP', 'HOEGH KOBE', 'VEHICLES CARRIER', 199.1, 'Seaway Agencies Pty Ltd', '/Date(1642654800000+1000)/', '/Date(1642669200000+1000)/', 'Wagners', 'SEA', 'SCHD', 'Auckland', 'Port Kembla', '68', 631289, 710], [132291, 334306, 'ARR', 'LOCH MAREE', 'BULK CARRIER', 176.83, 'Wave Shipping Pty Ltd', '/Date(1642655700000+1000)/', '/Date(1642672800000+1000)/', 'Point Cartwright Anchorage', 'Fisherman Island General Purpose Berth', 'SCHD', 'Fujairah', 'Lae', '9', 633744, 710], [132232, 334209, 'ARR', 'BLUE GRASS MARINER', 'TANKER', 183.06, 'Gulf Agency Company (Mackay)', '/Date(1642657200000+1000)/', '/Date(1642657260000+1000)/', 'Anch for MKY', 'Mackay Berth 1', 'SCHD', 'Gladstone', 'Singapore', None, 633566, 710], [132538, 334817, 'ARR', 'WINCANTON', 'LIQUEFIED GAS TANKER', 119.95, 'Inchcape Shipping Services (Queensland)', '/Date(1642657500000+1000)/', '/Date(1642668300000+1000)/', 'Fairway Buoy Anchorage', 'Fishermans Landing 5', 'CONF', 'Newcastle', 'Newcastle', '264', 632386, 725], [132473, 334686, 'EXT', 'GREAT CHEER', 'BULK CARRIER', 229.2, 'LBH Australia Pty Ltd (Mackay)', '/Date(1642658400000+1000)/', '/Date(1642658400000+1000)/', 'SEA for HPS', 'Anch for HPS & DBCT', 'PLAN', 'Kakogawa', 'Indonesia', '2201VC', 633677, 705], [132513, 334770, 'DEP', 'KAI YANG STAR', 'BULK CARRIER', 234.98, 'Wilhelmsen Ships Service (Weipa)', '/Date(1642659300000+1000)/', '/Date(1642666500000+1000)/', 'Lorim West', 'SEA', 'CONF', 'Dongjiakou', 'Qingdao', None, 633694, 725], [132575, 335351, 'EXT', 'IPSEA COLOSSUS', 'BULK CARRIER', 197.0, 'Monson Agencies Australia (Townsville & Abbot Point)', '/Date(1642662000000+1000)/', '/Date(1642662000000+1000)/', 'SEA', 'Abbot Point Anchorage', 'SCHD', 'Chittagong', None, None, 625240, 710], [132285, 334295, 'DEP', 'FW EXCURSIONIST', 'BULK CARRIER', 179.9, 'Wave Shipping Pty Ltd', '/Date(1642662000000+1000)/', '/Date(1642679100000+1000)/', 'Fisherman Island General Purpose Berth', 'SEA', 'SCHD', 'Busan', 'New Plymouth', '24', 633667, 710], [132364, 334463, 'EXT', 'JUPITER', 'BULK CARRIER', 225.0, 'LBH Australia Pty Ltd (Mackay)', '/Date(1642663800000+1000)/', '/Date(1642663800000+1000)/', 'SEA for DBCT', 'Anch for HPS & DBCT', 'PLAN', 'Rizhao', 'Singapore', '17', 633643, 705], [132781, 335342, 'DEP', 'MORNING CLARA', 'VEHICLES CARRIER', 199.9, 'Wilhelmsen Ships Service (Brisbane)', '/Date(1642665600000+1000)/', '/Date(1642680000000+1000)/', 'Fisherman Island No 1', 'SEA', 'SCHD', 'Tianjin', 'Port Kembla', '2251', 633093, 710], [131704, 333251, 'DEP', 'TANGGUH JAYA', 'LIQUEFIED GAS TANKER', 285.1, 'Wilhelmsen Ships Service (Gladstone)', '/Date(1642666500000+1000)/', '/Date(1642676400000+1000)/', 'Santos GLNG', 'SEA', 'CONF', 'Mexico', 'Incheon', None, 633458, 725], [130826, 331647, 'ARR', 'DL DAHLIA', 'BULK CARRIER', 229.0, 'Monson Agencies Australia (Gladstone)', '/Date(1642668300000+1000)/', '/Date(1642677300000+1000)/', 'Fairway Buoy Anchorage', 'Clinton Coal 1', 'CONF', 'Yeongheung', 'Tanjung Bin', '2712', 633296, 725], [132582, 334934, 'DEP', 'CORAL GEOGRAPHER', 'PASSENGER', 94.5, 'Coral Expeditions', '/Date(1642669200000+1000)/', '/Date(1642672800000+1000)/', 'C123', 'SEA', 'CONF', 'Cairns', 'Cairns', None, 633369, 725], [130422, 330911, 'DEP', 'NSU QUEST', 'BULK CARRIER', 299.94, 'Inchcape Shipping Services (Queensland)', '/Date(1642673700000+1000)/', '/Date(1642682700000+1000)/', 'Clinton Coal 3', 'SEA', 'CONF', 'Hay Point', 'Japan', '45', 632982, 725], [132795, 335383, 'REM', 'ALBATROSS BAY', 'LANDING CRAFT', 64.0, 'Sea Swift Pty Ltd', '/Date(1642674600000+1000)/', '/Date(1642676400000+1000)/', 'Horn Island', 'Main Jetty', 'CONF', 'Cairns', 'Seisia', 'AB 2203', 633274, 725], [132759, 335288, 'EXT', 'CMB PAUILLAC', 'BULK CARRIER', 235.0, 'Wilhelmsen Ships Service (Gladstone)', '/Date(1642675500000+1000)/', '/Date(1642679100000+1000)/', 'SEA', 'Fairway Buoy Anchorage', 'PLAN', 'Gove', 'Weipa', None, 633160, 705], [132430, 334596, 'DEP', 'GOLDEN YOSA', 'TANKER', 144.03, 'Sturrock Grindrod Maritime (Brisbane)', '/Date(1642676400000+1000)/', '/Date(1642692600000+1000)/', 'Viva Energy', 'SEA', 'SCHD', 'Geelong', 'Townsville', '74(C1)', 628015, 710], [132456, 334647, 'EXT', 'MISSY ENTERPRISE', 'GENERAL CARGO', 181.16, 'Wave Shipping Pty Ltd', '/Date(1642676400000+1000)/', '/Date(1642676460000+1000)/', 'SEA', 'Bundaberg Anchorage', 'PLAN', 'Singapore', 'Japan', '2', 631532, 705], [132389, 335619, 'EXT', 'GLOVIS CHORUS', 'VEHICLES CARRIER', 199.99, 'Gulf Agency Company (Brisbane)', '/Date(1642680000000+1000)/', '/Date(1642680000000+1000)/', 'SEA', 'Point Cartwright Anchorage', 'PLAN', 'Port Kembla', 'Pyeongtaek ', '77A', 630944, 705], [132505, 334744, 'EXT', 'NSU CHALLENGER', 'BULK CARRIER', 299.95, 'Gulf Agency Company (Gladstone)', '/Date(1642680000000+1000)/', '/Date(1642683600000+1000)/', 'SEA', 'Fairway Buoy Anchorage', 'PLAN', 'Nagoya', 'Oita', None, 633706, 705], [132727, 335219, 'EXT', 'RTM DIAS', 'BULK CARRIER', 234.87, 'Wilhelmsen Ships Service (Weipa)', '/Date(1642680900000+1000)/', '/Date(1642680900000+1000)/', 'SEA', 'Weipa Anchorage', 'PLAN', 'Gladstone', 'China', None, 633623, 705], [132859, 335500, 'ARR', 'FOURCROY', 'LANDING CRAFT', 49.8, 'Sea Swift Pty Ltd', '/Date(1642685400000+1000)/', '/Date(1642686900000+1000)/', 'SEA', 'Horn Island Barge Ramp', 'CONF', 'Saibai Island', 'Weipa', None, 633180, 725]], 'IsCustomMetaData': False, 'MetaData': {'__type': 'DataTableMetaDTO:#WebX.Core.DTO', 'Columns': [{'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'HAlignment': 'haright', 'Name': 'VOYAGE_ID', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'Voyage Id', 'Visible': False, 'Width': '50px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'HAlignment': 'haright', 'Name': 'ID', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'Id', 'Visible': False, 'Width': '20px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'Name': 'JOB_TYPE_CODE', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'Job Type', 'Visible': True, 'Width': '71px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '"link": {"title":"Ship Info", "type":"dashboard", "target":"_popup", "code":"standard.vesselinfo", "params":[{"name":"VID","value":"[%VESSEL_ID%]"}]}', 'Name': 'VESSEL_NAME', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'Ship', 'Visible': True, 'Width': '94px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'Name': 'MSQ_SHIP_TYPE', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'Ship Type', 'Visible': True, 'Width': '115px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'HAlignment': 'haright', 'Name': 'LOA', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'LOA', 'Visible': True, 'Width': '95px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'Name': 'AGENCY_NAME', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'Agency', 'Visible': True, 'Width': '287px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'Name': 'START_TIME', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'Start Time', 'Visible': True, 'Width': '91px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'Name': 'END_TIME', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'End Time', 'Visible': True, 'Width': '91px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'Name': 'FROM_LOCATION_NAME', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'From Location', 'Visible': True, 'Width': '139px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'Name': 'TO_LOCATION_NAME', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'To Location', 'Visible': True, 'Width': '139px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'Name': 'STATUS_TYPE_CODE', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'Status', 'Visible': True, 'Width': '83px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'Name': 'LASTPORT_NAME', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'Last Port', 'Visible': True, 'Width': '114px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'Name': 'NEXTPORT_NAME', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'Next Port', 'Visible': True, 'Width': '114px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'Name': 'VOYAGE_NUMBER', 'SortIndex': -1, 'SortOrder': '', 'Sortable': True, 'Template': '', 'Title': 'Voyage #', 'Visible': True, 'Width': '45px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'HAlignment': 'haright', 'Name': 'VESSEL_ID', 'SortIndex': -1, 'SortOrder': '', 'Template': '', 'Title': 'Vessel Id', 'Visible': False, 'Width': '64px'}, {'__type': 'ColumnMetaDTO:#WebX.Core.DTO', 'Format': '', 'HAlignment': 'haright', 'Name': 'STATUS_TYPE', 'SortIndex': -1, 'SortOrder': '', 'Template': '', 'Title': 'Status Type', 'Visible': False, 'Width': '64px'}], 'Script': 'var data = this.getData();\nvar $row = this.get$Row();\nvar $jobtype = this.get$Cell(\'JOB_TYPE\');\n\nvar $startTime = this.get$Cell(\'START_TIME\');\nvar $endTime = this.get$Cell(\'END_TIME\');\n\nif (data.JOB_TYPE == "Arrival")\n{\n $jobtype.css(\'color\', \'green\');\n}\nif (data.JOB_TYPE == "Departure")\n{\n $jobtype.css(\'color\', \'blue\');\n}\nif (data.JOB_TYPE == "Shift")\n{\n $jobtype.css(\'color\', \'#8B7500\');\n}\nif (data.JOB_TYPE == "External")\n{\n $jobtype.css(\'color\', \'grey\');\n}\n\nif (data.STATUS_TYPE >= 735 &&data.STATUS_TYPE < 750 )\n{\n $startTime.css(\'font-weight\', \'bold\');\n $endTime.css(\'font-weight\', \'bold\');\n $startTime.css(\'font-style\', \'italic\');\n $endTime.css(\'font-style\', \'italic\');\n}\n\n', 'TemplateRow': '', 'TemplateTable': '', 'Version': 0}, 'Name': 'DATA'}]}}
I've tried using pd.json_normalize with and without record_path. Specifying record_path draws an error where column name can't be found.
print(pd.json_normalize(my_dict))
Output:
d.__type d.BuildVersion d.ReportCode d.Tables
0 DataSetDTO:#WebX.Core.DTO 7.0.0.12590 MSQ-WEB-0001 [{'__type': 'DataTableDTO:#WebX.Core.DTO', 'Bu...
print(pd.json_normalize(my_dict, record_path=['Data']))
Error:
File "/Users/kevin_o'connell/opt/anaconda3/lib/python3.8/site-packages/pandas/io/json/_normalize.py", line 243, in _pull_field
result = result[spec]
KeyError: 'Data'
I've also tried the following but as the print out shows, I'm not returning the tabular information associated with Data.
print(pd.concat({k: pd.DataFrame(v).T for k, v in my_dict.items()}, axis=0))
0
d __type DataSetDTO:#WebX.Core.DTO
BuildVersion 7.0.0.12590
ReportCode MSQ-WEB-0001
Tables {'__type': 'DataTableDTO:#WebX.Core.DTO', 'Bui...
Returning the desired info as an object, not a pandas df:
df = pd.json_normalize(my_dict['d'], 'Tables')
df = pd.DataFrame(df['Data'].T)
Out:
Data
0 [[132393, 334520, EXT, CESI BEIHAI, LIQUEFIED ...
list meta as a parameter:
df = pd.json_normalize(my_dict['d'], record_path = 'Tables', meta = ['Data'], errors = 'ignore')
raise ValueError(
ValueError: Conflicting metadata name Data, need distinguishing prefix
record_path is the path to the record, so you should specify the full path
df = pd.json_normalize(data, record_path=['d', 'Tables', 'Data'])
If you want to do without record_path, the value type of Data is list of list. You can use pd.DataFrame directly
df = pd.DataFrame(data['d']['Tables'][0]['Data'])
print(df)
0 1 2 3 4 5 ... 11 12 13 14 15 16
0 132378 334489 EXT NANA Z BULK CARRIER 229.20 ... PLAN Keelung (Chilung) Kwangyang None 633086 705
1 132112 333984 DEP KRITI WARRIOR BULK CARRIER 234.98 ... CONF Amrun Amrun 2201 632395 725
2 132232 334208 EXT BLUE GRASS MARINER TANKER 183.06 ... PLAN Gladstone Singapore None 633566 705
3 132654 335076 EXT SERIFOS WARRIOR BULK CARRIER 234.98 ... PLAN Amrun Amrun 2201 632055 705
4 132030 333847 ARR MH GREEN CONTAINER SHIP 199.98 ... SCHD Yantian Botany Bay 11S/11N 633005 710
.. ... ... ... ... ... ... ... ... ... ... ... ... ...
71 132456 334647 EXT MISSY ENTERPRISE GENERAL CARGO 181.16 ... PLAN Singapore Japan 2 631532 705
72 132389 335619 EXT GLOVIS CHORUS VEHICLES CARRIER 199.99 ... PLAN Port Kembla Pyeongtaek 77A 630944 705
73 132505 334744 EXT NSU CHALLENGER BULK CARRIER 299.95 ... PLAN Nagoya Oita None 633706 705
74 132727 335219 EXT RTM DIAS BULK CARRIER 234.87 ... PLAN Gladstone China None 633623 705
75 132859 335500 ARR FOURCROY LANDING CRAFT 49.80 ... CONF Saibai Island Weipa None 633180 725
[76 rows x 17 columns]

how to scrape page inside the result card using BeatifulSoup?

<a href="https://magicpin.in/New-Delhi/Laxmi-Nagar/Restaurant/Bangalore-Ki-Famous-Biriyani/store/317630/?utm_source=search" data-type="around-merchant-card" onclick="sendEvent('web_searchlandingpage', 'click_search_merchant_card');">
<div class="merchant-logo-holder lazyloaded" data-bg="https://lh3.googleusercontent.com/UE8HJOOmV0hZsCbxbwQyha8UNa2ETY3-3zExps_mxUi-nbxVkgEBXo0kxghMHOUp87pge5tqIGrsU9Pu-iJ3h0_IETE=w64" style="background-image: url("https://lh3.googleusercontent.com/UE8HJOOmV0hZsCbxbwQyha8UNa2ETY3-3zExps_mxUi-nbxVkgEBXo0kxghMHOUp87pge5tqIGrsU9Pu-iJ3h0_IETE=w64");" title=", Laxmi Nagar, New Delhi"></div>
</a>
<div class="merchant-name-address">
<a href="https://magicpin.in/New-Delhi/Laxmi-Nagar/Restaurant/Bangalore-Ki-Famous-Biriyani/store/317630/?utm_source=search" data-type="around-merchant-card" onclick="sendEvent('web_searchlandingpage', 'click_search_merchant_card');">
<h3 class="merchant-name">
Bangalore Ki Famous Biriyani
</h3>
<h4 class="merchant-location">
Laxmi Nagar
, New Delhi
</h4>
</a>
<!--
<a href="" data-type="merchant_card_links" data-target="subcategory">
<h5 class="subcategory-tag"> </h5>
</a>
-->
</div>
<div class="rating" style="background-color: #8bcc00; border-color: #8bcc00;">
<img src="https://static.magicpin.com/samara/static/images/merchant/star-white.svg" class="star" onerror="this.onerror=null;this.alt='';recordBrokenImages(this,false,4);">
<span class="rating-value">3.7</span>
</div>
<section class="merchant-details">
<div class="cft-timing">
<article class="detail-heading cft-heading">Average Spent: </article>
<span class="detail-value">₹500</span>
</div>
<div class="merchant-attributes">
<div class="cover-holder">
<a href="https://magicpin.in/New-Delhi/Laxmi-Nagar/Restaurant/Bangalore-Ki-Famous-Biriyani/store/317630/?utm_source=search" data-type="around-merchant-card" onclick="sendEvent('web_searchlandingpage', 'click_search_merchant_card');">
<div class="merchant-cover lazyloaded" data-bg="https://lh3.googleusercontent.com/W70wpIcovlvssmLSpcyub4RjHABennVNRWxznclaxD7PEcZhdJrgygOwn5qJ3XrlYq9Yv90k-w2Ld0lTfaylBxIGmw=w512" style="background-image: url("https://lh3.googleusercontent.com/W70wpIcovlvssmLSpcyub4RjHABennVNRWxznclaxD7PEcZhdJrgygOwn5qJ3XrlYq9Yv90k-w2Ld0lTfaylBxIGmw=w512");" title=", Laxmi Nagar, New Delhi">
</div>
</a>
</div>
<div class="details">
<article class="detail-heading">Highlights: </article>
<span class="detail-value">
<span class="comma-separator">
Magic Weekend 14 16
</span>
<span class="comma-separator">
Mw 20200123
</span>
</span>
</div>
</div>
</section>
<div class="merchant-card-actions">
<div class="action claim-deal-button-react show-mb" data-sku="food_1158872_other" data-merchantname="Bangalore Ki Famous Biriyani" data-dealid="1164110">
<p class="cashback">
CASHBACK<span>upto 10.0% OFF</span>
</p>
</div>
<a class="cashback hide-mb action" target="_blank" href="https://magicpin.in/deal/?dealId=1164110&userId=5290338">
CASHBACK<span>upto 10.0% OFF</span>
</a>
</div>
</div>
page URL - https://magicpin.in/Delhi/search/?dist=10&query=biriyani&rt=3
this page contains some restaurants card now while scrapping the page in the loop I want to go inside the restaurant card and scrape the no. of reviews from inside it, I don't know how to do it I used this code to scrape front page
import requests
from bs4 import BeautifulSoup
import pandas as pd
url = "https://magicpin.in/Delhi/search/?dist=10&query=biriyani&rt=3" # URL of the website
header = {'User-Agent':'Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36'} # Temporary user agent
r = requests.get(url, headers=header)
soup = BeautifulSoup(r.content, 'html.parser')
divs = soup.find_all('div', class_ ="merchant-card-single")
for item in divs:
title = item.find('h3').text.strip() # restaurant name
loc = item.find('h4', class_ ="merchant-location").text.strip() # restaurant location
try: # used this try and except method because some restaurants are unrated and while scrpaping those we would run into an error
rating = item.find('div', class_="rating").text
except:
rating = None
pricce = item.find('div', class_="cft-timing").text.strip() # price for biriyani
biry_del = {
'name': title,
'location': loc,
'rating': rating,
'price': price
}
rest_list.append(biry_del)
I hope you guys understood please ask in comment for any confusion.
Note: Code in your question is not valid, variables are not defined or have typos and there is no expected result - So it is just a hint in the right direction
What happens?
Take a look into your soup, there is no <div> that contains the rating.
How to fix?
Select more specific - Rating is stored in a <span> with class rating-value:
rating = item.find('span', class_="rating-value").text
EDIT
Based on your comment you wanna switch to details and do things there - Just grab the url from <a> and perform another request:
url = item.find('a').get('href')
detailsSoup = BeautifulSoup(requests.get(url).text)
### look into your detailsSoup to find what you are searching for ...
To grab the raiting details it would be better to use the existing api - Extract merchands id from url and grab the json data:
url = item.find('a').get('href')
mid = url.split('/')[-2]
ratings = requests.get(f'https://magicpin.in/sam-api/merchants/get_merchant_reviews/?merchantUserId={mid}').json()['data']
Example
import requests
from bs4 import BeautifulSoup
import pandas as pd
url = "https://magicpin.in/Delhi/search/?dist=10&query=biriyani&rt=3" # URL of the website
header = {'User-Agent':'Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36'} # Temporary user agent
r = requests.get(url, headers=header)
soup = BeautifulSoup(r.content, 'html.parser')
rest_list=[]
divs = soup.find_all('div', class_ ="merchant-card-single")
for item in divs:
title = item.find('h3').text.strip() # restaurant name
loc = item.find('h4', class_ ="merchant-location").text.strip() # restaurant location
try: # used this try and except method because some restaurants are unrated and while scrpaping those we would run into an error
rating = item.find('span', class_="rating-value").text
except:
rating = None
price = item.find('div', class_="cft-timing").text.strip() # price for biriyani
url = item.find('a').get('href')
mid = url.split('/')[-2]
ratings = requests.get(f'https://magicpin.in/sam-api/merchants/get_merchant_reviews/?merchantUserId={mid}').json()['data']
biry_del = {
'name': title,
'location': loc,
'rating': rating,
'ratings': ratings,
'price': price
}
rest_list.append(biry_del)
print(rest_list)
Output
[{'name': 'BBC, Best Biriyani & Chicken', 'location': 'Satyaniketan\n , New Delhi', 'rating': '4.4', 'ratings': [{'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2021-12-02T23:17:47+05:30', 'post_id': 945109867, 'review': '', 'user': {'name': 'Gulzar', 'vanity': '2 Followers', 'badge': None, 'total_visits': 13, 'total_spent': 17641, 'user_id': '10663391', 'description': '', 'deeplink': 'magicpin://profileuser?userId=10663391', 'profile_pic': 'https://lh3.googleusercontent.com/V-R22m0t7GAJGn-bOhzjWXywVWk-GgwT75aBGh5Bq3ZXku8npkIGbQaBCKgnkCwuDFXRlrmbOBhEOTNu3-tXRwjdJOqfw_D_7OSzqDk8=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2021-08-03T14:49:12+05:30', 'post_id': 940277857, 'review': '', 'user': {'name': 'Dattatray Aadhav', 'vanity': '31 Followers', 'badge': None, 'total_visits': 318, 'total_spent': 636061, 'user_id': '6194299', 'description': '', 'deeplink': 'magicpin://profileuser?userId=6194299', 'profile_pic': 'https://lh3.googleusercontent.com/5eA-UBjZ6PBwDD2Pgb15xREya5D9Mma4PEU2Ka4G9MDMR1qwNKGrJO5Z6FMT63SplMo_o8V7xWYTg_oMdh3PeiC1bXUr=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2021-08-03T14:46:52+05:30', 'post_id': 940277730, 'review': "Didn't like the promotions & discounts at this place", 'user': {'name': 'Anshika', 'vanity': '9 Followers', 'badge': None, 'total_visits': 56, 'total_spent': 28936, 'user_id': '9555088', 'description': '', 'deeplink': 'magicpin://profileuser?userId=9555088', 'profile_pic': 'https://lh3.googleusercontent.com/YXgpyigxHNH0OMNnOsYerRxfmHAxxDYd9nsxzSveKwEAV8wrJUYmwabrgu0Ah_GMd7Mup26WjbWtPu-kkTcby6ddCoPQZ1aOCioi1wY6=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 2, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2021-08-03T14:48:56+05:30', 'post_id': 940277460, 'review': 'Loved the quality of products, safety precautions, variety of options, and location of store at this place', 'user': {'name': 'Priyank Jain', 'vanity': '118 Followers', 'badge': None, 'total_visits': 389, 'total_spent': 143081, 'user_id': '1140253', 'description': '', 'deeplink': 'magicpin://profileuser?userId=1140253', 'profile_pic': 'https://lh3.googleusercontent.com/nL4eRFh8Hi-b59CP4cL2cO57olZLxnL7yTiZ6xpoNLG67FQsGtEm-eTrKE9EaZ_cRtcR2TbldWxtqU2oG8Ob0x7Aag=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2021-08-03T14:46:56+05:30', 'post_id': 940277155, 'review': 'Loved the quality of products, safety precautions, variety of options, location of store, and promotions & discounts at this place', 'user': {'name': 'Naman', 'vanity': '5 Followers', 'badge': None, 'total_visits': 105, 'total_spent': 65821, 'user_id': '6148749', 'description': '19MaleChill', 'deeplink': 'magicpin://profileuser?userId=6148749', 'profile_pic': 'https://lh3.googleusercontent.com/C5UMTYVWkz1mNFUKWDfYKtCKDHoSUIrHsifJ7kfWrmJUBxjjyLW1lS0gOs4H31dekHdAXESRwN8cnqKVvxbY4P8GpRihVnZflujJfAjS=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2021-01-28T11:56:12+05:30', 'post_id': 932109603, 'review': 'Loved the range of products, delivery time, and promotions & discounts at this place', 'user': {'name': 'sunil', 'vanity': '', 'badge': None, 'total_visits': 2, 'total_spent': 586, 'user_id': '10156497', 'description': '', 'deeplink': 'magicpin://profileuser?userId=10156497', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-18T16:31:55+05:30', 'post_id': 929075104, 'review': '', 'user': {'name': 'Vrj', 'vanity': '', 'badge': None, 'total_visits': 11, 'total_spent': 34353, 'user_id': '7455242', 'description': '', 'deeplink': 'magicpin://profileuser?userId=7455242', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 4, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-18T16:32:42+05:30', 'post_id': 929074944, 'review': '', 'user': {'name': 'Vaibhav Deshatavar', 'vanity': '2 Followers', 'badge': None, 'total_visits': 26, 'total_spent': 7571, 'user_id': '4271349', 'description': '', 'deeplink': 'magicpin://profileuser?userId=4271349', 'profile_pic': 'https://lh3.googleusercontent.com/LbU80bZNxLLQ_bhc2VqWc6CJXHyqcNCLpBg5YBKMFWogWepbIyen3rdQIZx6WRZjT5l1OR63OLpZOuSVnz2TGXpP4pY=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': 'Niceeee ', 'review_date': '2020-12-18T12:38:07+05:30', 'post_id': 929056653, 'review': 'Loved the range of products, quality of products, delivery time, safe packaging, and promotions & discounts at this place', 'user': {'name': 'JAGGU RAJ', 'vanity': '', 'badge': None, 'total_visits': 3, 'total_spent': 3877, 'user_id': '9567167', 'description': '', 'deeplink': 'magicpin://profileuser?userId=9567167', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-18T09:44:06+05:30', 'post_id': 929047869, 'review': '', 'user': {'name': 'Ramya', 'vanity': '', 'badge': None, 'total_visits': 40, 'total_spent': 307540, 'user_id': '7769558', 'description': '', 'deeplink': 'magicpin://profileuser?userId=7769558', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-18T09:43:13+05:30', 'post_id': 929047672, 'review': '', 'user': {'name': 'Hemraj', 'vanity': '', 'badge': None, 'total_visits': 9, 'total_spent': 7636, 'user_id': '9840082', 'description': '', 'deeplink': 'magicpin://profileuser?userId=9840082', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-18T09:41:35+05:30', 'post_id': 929046779, 'review': 'Loved the quality of service, ambience, safety precautions, and taste at this place', 'user': {'name': 'Rahul', 'vanity': '1 Followers', 'badge': None, 'total_visits': 17, 'total_spent': 6594, 'user_id': '8723539', 'description': '', 'deeplink': 'magicpin://profileuser?userId=8723539', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-17T20:44:06+05:30', 'post_id': 929030684, 'review': 'Loved the quality of products and delivery time at this place', 'user': {'name': 'Mohit', 'vanity': '', 'badge': None, 'total_visits': 4, 'total_spent': 1086, 'user_id': '9878699', 'description': '', 'deeplink': 'magicpin://profileuser?userId=9878699', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T22:12:24+05:30', 'post_id': 928845159, 'review': 'Loved the quality of products, safety precautions, variety of options, location of store, and promotions & discounts at this place', 'user': {'name': 'Vishal Sorap', 'vanity': '11 Followers', 'badge': None, 'total_visits': 39, 'total_spent': 44997, 'user_id': '2379680', 'description': '', 'deeplink': 'magicpin://profileuser?userId=2379680', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T22:06:28+05:30', 'post_id': 928844059, 'review': '', 'user': {'name': 'Harshal Rane', 'vanity': '58 Followers', 'badge': None, 'total_visits': 286, 'total_spent': 1263268, 'user_id': '1615250', 'description': '', 'deeplink': 'magicpin://profileuser?userId=1615250', 'profile_pic': 'https://lh3.googleusercontent.com/9eADr5gEJeWHS17inAcfrbke3k-aYBzm-3f6JoP2Kzkljf2sP6-fHE5hxbMw7EI7Hk3q8eZa-gGE1Zes_bXLNDcrpuc=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 3, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': 'Everything \n', 'review_date': '2020-12-14T22:12:22+05:30', 'post_id': 928843503, 'review': 'Loved the quality, service, safety precautions, and promotions at this place', 'user': {'name': 'Aman Bhagat', 'vanity': '28 Followers', 'badge': None, 'total_visits': 48, 'total_spent': 33812, 'user_id': '6589071', 'description': '', 'deeplink': 'magicpin://profileuser?userId=6589071', 'profile_pic': 'https://lh3.googleusercontent.com/jtEV_8v2CjIcrJTPLhL_me_flmHxOwrCesP6Z7J24Y-jvYWWfVvOjUcCCUZ2cvVD55wtUGtn9YupoqSuFyttXGaC6aw=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T22:08:00+05:30', 'post_id': 928842848, 'review': 'Loved the range of products, quality of products, and delivery time at this place', 'user': {'name': 'Ashok Kumar Baghel', 'vanity': '', 'badge': None, 'total_visits': 79, 'total_spent': 78554, 'user_id': '9374043', 'description': '', 'deeplink': 'magicpin://profileuser?userId=9374043', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T22:05:44+05:30', 'post_id': 928841967, 'review': '', 'user': {'name': 'Akash dutt', 'vanity': '5 Followers', 'badge': None, 'total_visits': 196, 'total_spent': 711777, 'user_id': '7182223', 'description': '', 'deeplink': 'magicpin://profileuser?userId=7182223', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T22:07:11+05:30', 'post_id': 928841156, 'review': 'Loved the quality of service, ambience, safety precautions, taste, and price, promotions, & discounts at this place', 'user': {'name': 'Raunak', 'vanity': '44 Followers', 'badge': None, 'total_visits': 250, 'total_spent': 81010, 'user_id': '9210632', 'description': 'I am no one interesting', 'deeplink': 'magicpin://profileuser?userId=9210632', 'profile_pic': 'https://lh3.googleusercontent.com/-RVyHuI5_SABCC0LtLtV2oSCYmTyAJWJ-bv9ZX0lQY7tv6cdJIK0sW7BYTni2Pd6lv7Bb-Te1COJcQa9-2uWf3nkTcY=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T21:57:57+05:30', 'post_id': 928840295, 'review': 'Loved the variety of options, safety precautions, helpful staff, and price, promotions, & discounts at this place', 'user': {'name': 'Prashanth', 'vanity': '8 Followers', 'badge': None, 'total_visits': 75, 'total_spent': 374044, 'user_id': '9821253', 'description': '', 'deeplink': 'magicpin://profileuser?userId=9821253', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T22:02:35+05:30', 'post_id': 928840224, 'review': 'Loved the range of products at this place', 'user': {'name': 'Sushant P', 'vanity': '39 Followers', 'badge': None, 'total_visits': 407, 'total_spent': 358857, 'user_id': '4789975', 'description': '', 'deeplink': 'magicpin://profileuser?userId=4789975', 'profile_pic': 'https://lh3.googleusercontent.com/_AWRlRrTsNUdZDKyB4mTeFK99T2gM29ScDGVt8j1C5NemAprx_gw3OofqS3_cm4cELfpWWzIie55YYHYHTpLEQ2rpqs=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 4, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': 'Amazon is best ', 'review_date': '2020-12-14T21:55:10+05:30', 'post_id': 928839174, 'review': 'Loved the delivery time and promotions & discounts at this place', 'user': {'name': 'Sunny', 'vanity': '6 Followers', 'badge': None, 'total_visits': 24, 'total_spent': 40934, 'user_id': '9768929', 'description': '', 'deeplink': 'magicpin://profileuser?userId=9768929', 'profile_pic': 'https://lh3.googleusercontent.com/dDT5_ubc0MRR6y541WX6kGbqBBcm7xqeFxBPRUZgTO-x8hLF7fEzEkKzgwhq1r8wPDck-xtZCj99PyrO_i8xQgCA_-KyVV00kS31wBfS=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T22:01:07+05:30', 'post_id': 928838737, 'review': 'Loved the quality of service, ambience, and taste at this place', 'user': {'name': 'Sohil Merchant', 'vanity': '5 Followers', 'badge': None, 'total_visits': 199, 'total_spent': 98483, 'user_id': '9222147', 'description': '', 'deeplink': 'magicpin://profileuser?userId=9222147', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T21:52:45+05:30', 'post_id': 928838145, 'review': '', 'user': {'name': 'pinki', 'vanity': '1 Followers', 'badge': None, 'total_visits': 7, 'total_spent': 3207, 'user_id': '9836153', 'description': '', 'deeplink': 'magicpin://profileuser?userId=9836153', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T22:10:12+05:30', 'post_id': 928838005, 'review': '', 'user': {'name': 'Sudhanshu Shekhar', 'vanity': '3 Followers', 'badge': None, 'total_visits': 78, 'total_spent': 522579, 'user_id': '8217943', 'description': '', 'deeplink': 'magicpin://profileuser?userId=8217943', 'profile_pic': 'https://lh3.googleusercontent.com/PduS8X6YNq_gCRe_1sQ0zi6LFDalhGoeDeV_M7BJg_szWV7TLeqm2QotxNMczJDjLEQzJjTq7H3tAEtHLiDobBBguLBc=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 2, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T22:01:58+05:30', 'post_id': 928837918, 'review': 'Loved the ambience and taste at this place', 'user': {'name': 'Sandip Raul', 'vanity': '43 Followers', 'badge': None, 'total_visits': 87, 'total_spent': 257686, 'user_id': '3179212', 'description': '', 'deeplink': 'magicpin://profileuser?userId=3179212', 'profile_pic': 'https://lh3.googleusercontent.com/3nl1P7BGqdGiVdEGzjJ24SnV-aPDSe8KUv38d_kvo6G82NefqsVvlMN4l9AbDPhldMlWDN7JUgjzQvp9gKNFr9Sz1jt7K4nskEOIkXU=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T21:58:06+05:30', 'post_id': 928837904, 'review': 'Loved the quality of products, safety precautions, variety of options, location of store, and promotions & discounts at this place', 'user': {'name': 'Killer', 'vanity': '7 Followers', 'badge': None, 'total_visits': 28, 'total_spent': 21599, 'user_id': '7412507', 'description': '', 'deeplink': 'magicpin://profileuser?userId=7412507', 'profile_pic': 'https://lh3.googleusercontent.com/_fhBywD7kvez24utn17OhvtbYK-jMvnL9frdFLPxV_vJk2lILIkLE6FRxW58mfTZRBHNB0im-nSGE6GSzLJ3ULJMsgzC=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T22:05:34+05:30', 'post_id': 928837839, 'review': 'Loved the range of products, quality of products, delivery time, safe packaging, and promotions & discounts at this place', 'user': {'name': 'Axat', 'vanity': '', 'badge': None, 'total_visits': 26, 'total_spent': 22707, 'user_id': '9571962', 'description': '', 'deeplink': 'magicpin://profileuser?userId=9571962', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T21:52:34+05:30', 'post_id': 928837057, 'review': '', 'user': {'name': 'Manna11', 'vanity': '', 'badge': None, 'total_visits': 3, 'total_spent': 1209, 'user_id': '9840078', 'description': '', 'deeplink': 'magicpin://profileuser?userId=9840078', 'profile_pic': '', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 4, 'reply_date': '0001-01-01T00:00:00Z'}, {'rating_text': 'Outlet Rating', 'reply': '', 'merchant': None, 'review_title': '', 'review_date': '2020-12-14T22:10:41+05:30', 'post_id': 928836452, 'review': 'Loved the range of products at this place', 'user': {'name': 'Rushikesh Ingale', 'vanity': '23 Followers', 'badge': None, 'total_visits': 116, 'total_spent': 217734, 'user_id': '6911448', 'description': '', 'deeplink': 'magicpin://profileuser?userId=6911448', 'profile_pic': 'https://lh3.googleusercontent.com/-fb2w-cH1_0rjjoK2GYQDYr1tu_SAF_NyLN7eUHvTATCwO9fP6QEaV_wd6blNamjhJ5radva3axs03SDO46HVhYosPI=s120', 'is_following': False}, 'media_list': [{'image_url': '', 'aspect_ratio': 1}], 'rating': 5, 'reply_date': '0001-01-01T00:00:00Z'}], 'price': 'Average Spent: \n₹350'}]

Need help translating a nested dictionary into a pandas dataframe

Looking into translating the following nested dictionary which is an API pull from Yelp into a pandas dataframe to run visualization on:
Top 50 Pizzerias in Chicago
{'businesses': [{'alias': 'pequods-pizzeria-chicago',
'categories': [{'alias': 'pizza', 'title': 'Pizza'}],
'coordinates': {'latitude': 41.92187, 'longitude': -87.664486},
'display_phone': '(773) 327-1512',
'distance': 2158.7084581522413,
'id': 'DXwSYgiXqIVNdO9dazel6w',
'image_url': 'https://s3-media1.fl.yelpcdn.com/bphoto/8QJUNblfCI0EDhOjuIWJ4A/o.jpg',
'is_closed': False,
'location': {'address1': '2207 N Clybourn Ave',
'address2': '',
'address3': '',
'city': 'Chicago',
'country': 'US',
'display_address': ['2207 N Clybourn Ave',
'Chicago, IL 60614'],
'state': 'IL',
'zip_code': '60614'},
'name': "Pequod's Pizzeria",
'phone': '+17733271512',
'price': '$$',
'rating': 4.0,
'review_count': 6586,
'transactions': ['restaurant_reservation', 'delivery'],
'url': 'https://www.yelp.com/biz/pequods-pizzeria-chicago?adjust_creative=wt2WY5Ii_urZB8YeHggW2g&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=wt2WY5Ii_urZB8YeHggW2g'},
{'alias': 'lou-malnatis-pizzeria-chicago',
'categories': [{'alias': 'pizza', 'title': 'Pizza'},
{'alias': 'italian', 'title': 'Italian'},
{'alias': 'sandwiches', 'title': 'Sandwiches'}],
'coordinates': {'latitude': 41.890357,
'longitude': -87.633704},
'display_phone': '(312) 828-9800',
'distance': 4000.9990531720227,
'id': '8vFJH_paXsMocmEO_KAa3w',
'image_url': 'https://s3-media3.fl.yelpcdn.com/bphoto/9FiL-9Pbytyg6usOE02lYg/o.jpg',
'is_closed': False,
'location': {'address1': '439 N Wells St',
'address2': '',
'address3': '',
'city': 'Chicago',
'country': 'US',
'display_address': ['439 N Wells St',
'Chicago, IL 60654'],
'state': 'IL',
'zip_code': '60654'},
'name': "Lou Malnati's Pizzeria",
'phone': '+13128289800',
'price': '$$',
'rating': 4.0,
'review_count': 6368,
'transactions': ['pickup', 'delivery'],
'url': 'https://www.yelp.com/biz/lou-malnatis-pizzeria-chicago?adjust_creative=wt2WY5Ii_urZB8YeHggW2g&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=wt2WY5Ii_urZB8YeHggW2g'},
....]
I've tried the below and iterations of it but haven't had any luck.
df = pd.DataFrame.from_dict(topresponse)
Im really new to coding so any advice would be helpful
response["businesses"] is a list of records, so:
df = pd.DataFrame.from_records(response["businesses"])

how to find the no. of person from a particular country from the below code?

[
{'Year': 1901,
'Category': 'Chemistry',
'Prize': 'The Nobel Prize in Chemistry 1901',
'Motivation': '"in recognition of the extraordinary services he has rendered by the discovery of the laws of chemical dynamics and osmotic pressure in solutions"',
'Prize Share': '1/1',
'Laureate ID': 160,
'Laureate Type': 'Individual',
'Full Name': "Jacobus Henricus van 't Hoff",
'Birth Date': '1852-08-30',
'Birth City': 'Rotterdam',
'Birth Country': 'Netherlands',
'Sex': 'Male',
'Organization Name': 'Berlin University',
'Organization City': 'Berlin',
'Organization Country': 'Germany',
'Death Date': '1911-03-01',
'Death City': 'Berlin',
'Death Country': 'Germany'},
{'Year': 1901,
'Category': 'Literature',
'Prize': 'The Nobel Prize in Literature 1901',
'Motivation': '"in special recognition of his poetic composition, which gives evidence of lofty idealism, artistic perfection and a rare combination of the qualities of both heart and intellect"',
'Prize Share': '1/1',
'Laureate ID': 569,
'Laureate Type': 'Individual',
'Full Name': 'Sully Prudhomme',
'Birth Date': '1839-03-16',
'Birth City': 'Paris',
'Birth Country': 'France',
'Sex': 'Male',
'Organization Name': '',
'Organization City': '',
'Organization Country': '',
'Death Date': '1907-09-07',
'Death City': 'Châtenay',
'Death Country': 'France'}
]
If you want to find, how many person belong to same birth country only from given list of dict, you can use the following code :
from collections import Counter
li = [each['Birth City'] for each in val if each['Birth City']]
print(dict(Counter(li)))
OUTPUT
{'Rotterdam': 1, 'Paris': 1}

Categories

Resources