Monday, July 17, 2023

How to Convert a Dictionary Into a Pandas DataFrame - Built In - Dictionary

Pandas is a popular Python data library that provides a powerful API that lets developers analyze and manipulate data

One of the most common tasks when working with Python and Pandas is converting a dictionary into a DataFrame. This can be extremely useful when you’d like to perform a quick analysis or data visualization that is currently stored in a dictionary data structure.

3 Ways to Convert a Dictionary to DataFrame

  1. pandas.DataFrame.from_dict Method: This allows you to create a DataFrame from dict of array-like or dicts objects when the dictionary keys correspond to the DataFrame columns. 
  2. orient='index' Option: When calling from_dict, this option ensures the key-value is parsed as a DataFrame row.
  3. orient='tight' Option: This is most useful for creating MultiIndex DataFrames. It assumes that the input dictionary has the following keys: 'index', 'columns', 'data', 'index_names' and 'column_names'.  

In this article, we’ll explore different ways to convert a Python dictionary into a Pandas DataFrame based on how the data is structured and stored originally in a dict.

Convert a Dictionary Into a DataFrame

In order to convert a Python dictionary to a Pandas DataFrame, we can use the pandas.DataFrame.from_dict method to construct DataFrames from dict of array-like or dicts objects.

Let’s create an example Python dictionary with some dummy values that we’ll continue using in the next few sections. This will help us demonstrate some interesting ways for converting it into a Pandas DataFrame.

users = {
  'fist_name': ['John', 'Andrew', 'Maria', 'Helen'],
  'last_name': ['Brown', 'Purple', 'White', 'Blue'],
  'is_enabled': [True, False, False, True],
  'age': [25, 48, 76, 19]
}

In this example dictionary, the keys correspond to DataFrame columns, while every element in the list corresponds to the row-value for that particular column. Therefore, we can (optionally) specify the orient to be equal to 'columns'.

import pandas as pd 


users = {
  'fist_name': ['John', 'Andrew', 'Maria', 'Helen'],
  'last_name': ['Brown', 'Purple', 'White', 'Blue'],
  'is_enabled': [True, False, False, True],
  'age': [25, 48, 76, 19]
}


df = pd.DataFrame.from_dict(users)

We’ve just created a Pandas DataFrame using a Python dictionary.

print(df)

  fist_name last_name  is_enabled  age
0      John     Brown        True   25
1    Andrew    Purple       False   48
2     Maria     White       False   76
3     Helen      Blue        True   19

This approach only applies whenever your data in the dictionary is structured in such a way that every key corresponds to the DataFrame columns. But what happens if we have a different structure?

More on Python10 Ways to Convert Lists in Python Dictionaries

Converting Dictionary to DataFrame With Orient=‘Index’

Now, let’s assume that we have a dictionary whose keys correspond to the rows of the DataFrame we’d like to create.

users = {
  'row_1': ['John', 'Brown', True, 25],
  'row_2': ['Andrew', 'Purple', False, 48],
  'row_3': ['Maria', 'White', False, 76],
  'row_4': ['Helen', 'Blue', True, 19],
}

We’ll have to use the orient='index' option such that every key-value pair in our dictionary is parsed as a DataFrame row. When using orient='index', we must explicitly specify the column names when calling from_dict() method:

import pandas as pd

users = {
  'row_1': ['John', 'Brown', True, 25],
  'row_2': ['Andrew', 'Purple', False, 48],
  'row_3': ['Maria', 'White', False, 76],
  'row_4': ['Helen', 'Blue', True, 19],
}

cols = ['first_name', 'last_name', 'is_enabled', 'age']
df = pd.DataFrame.from_dict(users, orient='index', columns=cols)

And once again, we managed to construct a Pandas DataFrame out of a Python dictionary, this time by parsing every key-value pair as a DataFrame row:

print(df)

      first_name last_name  is_enabled  age
row_1       John     Brown        True   25
row_2     Andrew    Purple       False   48
row_3      Maria     White       False   76
row_4      Helen      Blue        True   19

As you may have noticed, every key also became an index to the newly populated DataFrame. If you wish to get rid of it, you can do so by running the following commands:

df.reset_index(drop=True, inplace=True)

And the index should now be reset:

print(df)


  first_name last_name  is_enabled  age
0       John     Brown        True   25
1     Andrew    Purple       False   48
2      Maria     White       False   76
3      Helen      Blue        True   19

Convert Dictionary to DataFrame Using Orient=‘Tight’ 

As of Pandas v1.4.0, you can also use the orient='tight' option to construct a Pandas DataFrames from Python dictionaries. This option assumes that the input dictionary has the following keys: 'index', 'columns', 'data', 'index_names' and 'column_names'.

For example, the following dictionary matches this requirement:

data = {
  'index': [('a', 'b'), ('a', 'c')],
  'columns': [('x', 1), ('y', 2)],
  'data': [[1, 3], [2, 4]],
  'index_names': ['n1', 'n2'],
  'column_names': ['z1', 'z2']
}

df = pd.DataFrame.from_dict(data, orient='tight')


print(df)
z1     x  y
z2     1  2
n1 n2      
a  b   1  3
   c   2  4

This final approach is typically useful for constructing MultiIndex DataFrames.

A tutorial on how to convert dictionary to DataFrame. | Video: Erik Marsja

More on Pandas8 Ways to Filter Pandas DataFrame

Common Methods to Convert Dictionary to DataFrame 

Converting a Python dictionary into a Pandas DataFrame is a simple and straightforward process. By using the pd.DataFrame.from_dict method along with the correct orient option according to the way your original dictionary is structured, you can easily transform your data into a DataFrame to perform data analysis or transformation using the Pandas API.

Adblock test (Why?)

Organizers close the books on ‘The Dictionary Project” - The Republic - Dictionary

After nearly two decades of providing “a little yellow” gift to every third-grader in the county, organizers have announced they are closing the books on the annual “Dictionary Project.”

Since it began nearly 20 years ago, more than 20,000 dictionaries, including Spanish and Japanese versions, have been distributed to area third-graders in public, private and homeschool classrooms as well as adult literacy and English language programs, according to the Heritage Fund — The Community Foundation of Bartholomew County.

But partners have decided improvements in technology since the project began have lessened the demand for paperback dictionaries as a quick reference tool.

The local “Dictionary Project” was made possible through annual grant funding from Heritage Fund and distributed by Bartholomew Retired Teachers Association with support from IUPUC Center for Teaching and Learning, Heritage Fund officials said.

In 2004, Lyn Morgan, former grants manager at Heritage Fund, researched the national program and brought the idea to center for help with offering it locally.

The partners believed reading was the most important skill for students to master and hoped the dictionaries helped children expand their vocabularies, encouraging them to “look it up!” Nationally more than 35 million third-graders have received personal dictionaries as part of the program.

Past and current third-grade educators thanked organizers for the years of dictionary distributions, which they said not only benefited students’ vocabularies but also taught ownership and responsibility.

“You all have, no doubt, made a lasting impression on all of them! What an incredible gift you have given to each of our students over time,” Southside Elementary teacher Robin Kiel said.

As part of its strategic impact area of positive Youth Development, Heritage Fund will continue to explore opportunities to support students in the community, Heritage Fund officials said.

Adblock test (Why?)

Puss In Boots 2 Translation Guide – Gazpacho, Perrito & 13 Other Spanish Words & Phrases To Know - Screen Rant - Translation

[unable to retrieve full-text content]

Puss In Boots 2 Translation Guide – Gazpacho, Perrito & 13 Other Spanish Words & Phrases To Know  Screen Rant

Sunday, July 16, 2023

Japanese dictionary of 'otaku' terms by J-pop, K-pop fans to hit bookstores - The Mainichi - The Mainichi - Dictionary

Associate professor Yoshiko Koide, right, and her seminar students working on making an otaku terminology dictionary, are seen at Nagoya College in Toyoake, Aichi Prefecture, on May 25, 2023. (Mainichi/Shinichiro Kawase)

NAGOYA -- A dictionary of "otaku" terminology written by college students who are passionate about Johnny & Associates Inc.'s idols, K-pop artists and other interests will be published this fall.

Tokyo-based Sanseido Co., known for its Japanese dictionaries, has turned its attention to the power of otaku, or geeks, as it seeks to cultivate new demand amid sluggish dictionary sales.

What inspired the publication was "Daigenkai (the great limit)," a dictionary of otaku terms created by students at Nagoya College in Toyoake, Aichi Prefecture, in a seminar class in the fall of 2022. The name was derived from "Daigenkai (the great sea of words)" -- an enlarged and revised edition of "Genkai (the sea of words)," Japan's first modern dictionary -- and "genkai otaku," which refers to "otaku whose embarrassing behavior exceeds the limit."

Divided into 11 chapters, including idols, anime and games, the soon-to-be-published dictionary contains a total of 821 words. For example, the entry for "chokkon" is "the first day of a concert. It is used to abbreviate the word 'concert' by adding the Korean word 'cho = beginning' to it." Many of the words would be unfamiliar unless you were a committed nerd of a particular pop culture genre. The original dictionary created by the students was very popular at their college festival, with some people coming all the way from Tokyo to buy it.

The students' dictionary also became a hot topic on social media. When Sanseido editor Kentaro Okugawa, 54, ordered a copy of the dictionary as a reference book, it was so well received within the company that some employees commented, "The students' passion really comes through," and, "This is just the most interesting thing." Associate professor Yoshiko Koide, who teaches the Nagoya College class, approached the publisher about publishing the dictionary, and it was quickly given the green light.

The five new members of the seminar class are busy adding and revising the terminology, and doing illustrations so that the dictionary will be ready in time for the college festival in November. Erina Kato, 19, the seminar's head student and a self-proclaimed K-pop otaku, hopes that "not only will otaku relate to the dictionary, but that people who have no connection to otaku will also learn that this world exists."

(Japanese original by Shinichiro Kawase, Nagoya News Center)

Adblock test (Why?)

Google Translate Decodes World's Oldest Language with AI - Analytics Insight - Translation

Google

An ancient language with roughly untranslated documents now has a translator that works in minutes AI

The world’s oldest language, Akkadian, was translated using artificial intelligence (AI) by a mixed team of computer scientists and historians. The team, led by a Google software engineer and an Assyriologist from Ariel University, used the same technology that powers Google Translate to construct an AI model capable of instantaneously reading the ancient characters found on cuneiform tablets. 

Akkadian, the language of the Akkadian Empire that flourished in modern-day Iraq from the 24th to 22nd century BCE, presents unique translation issues. Understanding its meaning is like going without a North Star since there are no descendant languages and a lack of cultural background. The Akkadian writing system used cuneiform, distinguished by sharp, intersecting triangular symbols carved on clay tablets with the wedge-shaped end of a reed. Yet, because of their sheer volume and the restricted number of specialists who can read them, most of these texts remain untranslated and unavailable.

The vastness of existing cuneiform writings significantly outnumbers the small number of Akkadian linguists. As a result, a great bank of information about this critical early civilization, frequently referred to as the world’s first empire, remains unexplored. Linguistic attempts to translate Akkadian writings need help to keep up with the growing quantity of tablets uncovered by archaeologists. On the other hand, the incorporation of AI into the cuneiform interpretation process has the potential to change this environment.

The AI model developed by the team specializes in two types of translation cuneiform to English translation and cuneiform transliteration. The model’s translation quality, as judged by the Best Bilingual Evaluation Understudy 4 score, produced outstanding results. The model outperformed the team’s expectations, scoring 36.52 and 37.47 for the two translation categories and providing high-quality translations. The BLEU4 score goes from 0 to 100, with 70 representing the best possible result for a highly experienced human translation. 

Computer-generated translations have always been fragile and untrustworthy, unable to grasp the full complexity of idioms and nonliteral language that defy conventional grammatical constraints. Recent advances in artificial intelligence, such as the cuneiform translator, have dug into the more delicate parts of the language. Despite its outstanding accomplishments, the cuneiform AI translator still creates mistakes and hallucinations, which are frequent in AI systems. The AI model performs well for translating shorter lines and formulaic documents like administrative records. It also reproduces genre-specific characteristics during translation, which piqued the researchers’ interest. In the future, AI will be taught on greater samples of translations. The AI translator assists researchers by creating preliminary translations that human specialists may modify and check. 

Adblock test (Why?)

Saturday, July 15, 2023

'Dictionary Project' ends after 19 years - Local News Digital - Dictionary

'Dictionary Project' ends after 19 years

Courtesy - Heritage Fund.

COLUMBUS, Ind. – After nearly two decades of providing “a little yellow” gift to every third-grader in the county, organizers have announced they are closing the books on the annual “Dictionary Project.”

Since its start nearly 20 years ago, more than 20,000 dictionaries, including Spanish and Japanese versions, have been distributed to area third-graders in public, private, and homeschool classrooms as well as adult literacy and English language programs.

But, partners have decided improvements in technology since the project began have lessened the demand for paperback dictionaries as a quick reference tool.

The local “Dictionary Project” was made possible through annual grant funding from Heritage Fund and distributed by Bartholomew Retired Teachers Association with support from IUPUC Center for Teaching and Learning. In 2004, Lyn Morgan, former grants manager at Heritage Fund, researched the national program and brought the idea to CTL for help with offering it locally.

The partners believed reading was the most important skill for students to master and hoped the dictionaries helped children expand their vocabularies, encouraging them to “look it up!” Nationally more than 35 million third-graders have received personal dictionaries as part of the program.

As part of its strategic impact area of positive Youth Development, Heritage Fund will continue to explore opportunities to support students in the community.

Adblock test (Why?)

Student use of machine translation debated - Times Higher Education - Translation

Universities are being forced to reassess requirements for international students to compose their assignments in English, amid rapid improvements in artificial intelligence (AI) tools.

Helen Gniel, head of the integrity unit at Australia’s Tertiary Education Quality and Standards Agency, told a Melbourne conference that students’ use of machine translation technology was “a debate we have to have”.

Dr Gniel said students were using tools such as Google Translate to convert work from their first languages into English, then polishing it with proofreading apps such as Grammarly – practices they would undoubtedly continue in the workplace after graduation.

But such behaviour was problematic while they were still at university, she said, because of the expectation that they were educated in English. If courses had been delivered in other languages, institutions were legally required to note this on testamurs.

Dr Gniel said professional bodies also wanted reassurance that foreign graduates had “adequate language”, should they remain in Australia and work in places such as hospitals. “There’s a bigger question about what it is that we’re saying students can do at the end of our degrees,” Dr Gniel told the Australian Technology Network’s Future Learning Summit.

“How much is English language a part of that? What are we trying to assess, and why? I don’t think we’ve really given deep thought to what that means now, in a world of such ready translation tools.”

Phillip Dawson, associate director of Deakin University’s Centre for Research in Assessment and Digital Learning, criticised an “underlying” assumption that international students should be as capable in English as in their primary disciplines.

“If students think better in their own first language, what are they gaining out of hand translating rather than machine translating?” he asked.

Professor Dawson speculated that students submitting assignments on decolonisation could find themselves “in trouble” for not drafting their work in the coloniser’s language. “We have a lot of rhetoric around things like decolonising the curriculum, but we’re pretty strict on [how students] engage in it,” he said.

Ant Bagshaw, a higher education policy adviser with LEK Consulting, asked whether universities would find it acceptable for students to use live translation apps during oral examinations. Professor Dawson said it was a live question, amid the increasing use of interactive oral assessment to assess students’ learning outcomes.

He said international students’ “anxiety” around communicating in English could mask their mastery of their subjects. “To what extent can we assist students in those interactive oral assessments to better demonstrate how they’ve actually met the outcome?” he asked.

A recent literature review by Canadian PhD candidate Kate Paterson found that the “ethical and pedagogical implications” of students’ use of machine translation had not been “coherently addressed” by academics or tertiary institutions.

“Human-machine relationships…have the potential to destabilise traditional pedagogies and transform how we teach and learn languages and academic content,” she wrotes in the TESOL Journal. “The challenge…is to re-envision educational policy and practice in ways that maintain academic integrity and promote greater educational equity.”

john.ross@timeshighereducation.com

Adblock test (Why?)