In this Tutorial, I am going to experiment with the Table
class under the Datascience
module for some exploratory analysis of the Quran. Let us get started.
First, I used a Quran database already available under Kaggle and brought it under my folder.
below is the standard Kaggle prefix.
# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory
import os
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename))
# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All"
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
/kaggle/input/quran-makki-madani/quran-toc.csv
/kaggle/input/qurancsv/Quran.csv
/kaggle/input/quran-clean-without-araab/Quran-clean-without-aarab.csv
Next, I have to install the datascience
module using pip
. Full documentation of this module can be found here.
!pip install datascience
I have ignored the long output of executing the pip
function above. So, now let us bring the use of the Table
module under the datascience package.
from datascience import *
Here is the first step, reading the table using read_table
method.
q = Table.read_table('/kaggle/input/quran-clean-without-araab/Quran-clean-without-aarab.csv')
q
Unnamed: 0 | SurahNum | AyahNum | Ayah |
---|---|---|---|
0 | 1 | 1 | بسم الله الرحمن الرحيم |
1 | 1 | 2 | الحمد لله رب العالمين |
2 | 1 | 3 | الرحمن الرحيم |
3 | 1 | 4 | مالك يوم الدين |
4 | 1 | 5 | إياك نعبد وإياك نستعين |
5 | 1 | 6 | اهدنا الصراط المستقيم |
6 | 1 | 7 | صراط الذين أنعمت عليهم غير المغضوب عليهم ولا الضالين |
7 | 2 | 1 | بسم الله الرحمن الرحيم الم |
8 | 2 | 2 | ذلك الكتاب لا ريب فيه هدى للمتقين |
9 | 2 | 3 | الذين يؤمنون بالغيب ويقيمون الصلاة ومما رزقناهم ينفقون |
... (6226 rows omitted)
With Table
we can show certain number of rows from top, for example
q.show(3)
Unnamed: 0 | SurahNum | AyahNum | Ayah |
---|---|---|---|
0 | 1 | 1 | بسم الله الرحمن الرحيم |
1 | 1 | 2 | الحمد لله رب العالمين |
2 | 1 | 3 | الرحمن الرحيم |
... (6233 rows omitted)
Similarly we can selec certain columns only
q.select('Ayah')
Ayah |
---|
بسم الله الرحمن الرحيم |
الحمد لله رب العالمين |
الرحمن الرحيم |
مالك يوم الدين |
إياك نعبد وإياك نستعين |
اهدنا الصراط المستقيم |
صراط الذين أنعمت عليهم غير المغضوب عليهم ولا الضالين |
بسم الله الرحمن الرحيم الم |
ذلك الكتاب لا ريب فيه هدى للمتقين |
الذين يؤمنون بالغيب ويقيمون الصلاة ومما رزقناهم ينفقون |
... (6226 rows omitted)
How many rows are there in this quranic table. In other words, how many total Ayaat are there in the Quran?
q.num_rows
6236
let us see the last row
q.row(q.num_rows-1)
Row(Unnamed: 0=6235, SurahNum=114, AyahNum=6, Ayah='من الجنة والناس')
Counting Words
Let us see how you can apply
a function to each row of the Table.
Here is a function that given a sentence will return the number of words in that sentence.
def count_words(item):
return len(item.split())
Thus, we can apply
a function on a table as follows
q.apply(count_words, 'Ayah')
array([4, 4, 2, ..., 4, 5, 3])
given this we can write the following handy code,and assign the result to a new table called qwc
meaning quran with word counts.
qwc = q.with_columns("words", q.apply(count_words, 'Ayah'))
qwc
Unnamed: 0 | SurahNum | AyahNum | Ayah | words |
---|---|---|---|---|
0 | 1 | 1 | بسم الله الرحمن الرحيم | 4 |
1 | 1 | 2 | الحمد لله رب العالمين | 4 |
2 | 1 | 3 | الرحمن الرحيم | 2 |
3 | 1 | 4 | مالك يوم الدين | 3 |
4 | 1 | 5 | إياك نعبد وإياك نستعين | 4 |
5 | 1 | 6 | اهدنا الصراط المستقيم | 3 |
6 | 1 | 7 | صراط الذين أنعمت عليهم غير المغضوب عليهم ولا الضالين | 9 |
7 | 2 | 1 | بسم الله الرحمن الرحيم الم | 5 |
8 | 2 | 2 | ذلك الكتاب لا ريب فيه هدى للمتقين | 7 |
9 | 2 | 3 | الذين يؤمنون بالغيب ويقيمون الصلاة ومما رزقناهم ينفقون | 8 |
... (6226 rows omitted)
Let me rename the first coulumn from unnamed to SrNo
qwc = qwc.relabeled(0,'SrNo')
qwc
SrNo | SurahNum | AyahNum | Ayah | words |
---|---|---|---|---|
0 | 1 | 1 | بسم الله الرحمن الرحيم | 4 |
1 | 1 | 2 | الحمد لله رب العالمين | 4 |
2 | 1 | 3 | الرحمن الرحيم | 2 |
3 | 1 | 4 | مالك يوم الدين | 3 |
4 | 1 | 5 | إياك نعبد وإياك نستعين | 4 |
5 | 1 | 6 | اهدنا الصراط المستقيم | 3 |
6 | 1 | 7 | صراط الذين أنعمت عليهم غير المغضوب عليهم ولا الضالين | 9 |
7 | 2 | 1 | بسم الله الرحمن الرحيم الم | 5 |
8 | 2 | 2 | ذلك الكتاب لا ريب فيه هدى للمتقين | 7 |
9 | 2 | 3 | الذين يؤمنون بالغيب ويقيمون الصلاة ومما رزقناهم ينفقون | 8 |
... (6226 rows omitted)
qwc.row(qwc.num_rows-1)
Row(SrNo=6235, SurahNum=114, AyahNum=6, Ayah='من الجنة والناس', words=3)
Find English translation
Notice that the datasource we got does not have English translation. But kaggle has other datasources that has English translations. Sounds like a good use case for join
ing two tables. Let us do that.
en = Table.read_table('/kaggle/input/qurancsv/Quran.csv')
en
SrNo | JuzNo | SurahNo | AyahNo | EnglishTranslation | OrignalArabicText | ArabicText | ArabicWordCount | ArabicLetterCount |
---|---|---|---|---|---|---|---|---|
1 | 1 | 1 | 1 | In the name of Allah, Most Gracious, Most Merciful. | ?????? ??????? ???????????? ?????????? | ??? ???? ?????? ?????? | 4 | 19 |
2 | 1 | 1 | 2 | Praise be to Allah, the Cherisher and Sustainer of the w ... | ????????? ??????? ????? ????????????? | ????? ??? ?? ???????? | 4 | 18 |
3 | 1 | 1 | 3 | Most Gracious, Most Merciful; | ???????????? ?????????? | ?????? ?????? | 2 | 12 |
4 | 1 | 1 | 4 | Master of the Day of Judgment. | ??????? ?????? ???????? | ???? ??? ????? | 3 | 12 |
5 | 1 | 1 | 5 | Thee do we worship, and Thine aid we seek. | ???????? ???????? ?????????? ??????????? | ???? ???? ????? ?????? | 4 | 19 |
6 | 1 | 1 | 6 | Show us the straight way, | ???????? ?????????? ?????????????? | ????? ?????? ???????? | 3 | 19 |
7 | 1 | 1 | 7 | The way of those on whom Thou hast bestowed Thy Grace, t ... | ??????? ????????? ?????????? ?????????? ?????? ????????? ... | ???? ????? ????? ????? ??? ??????? ????? ??? ??????? | 9 | 44 |
8 | 1 | 2 | 1 | A. L. M. | ??? | ??? | 1 | 3 |
9 | 1 | 2 | 2 | This is the Book; in it is guidance sure, without doubt, ... | ??????? ?????????? ??? ?????? ? ????? ? ????? ?????????????? | ??? ?????? ?? ??? ? ??? ? ???? ??????? | 9 | 30 |
10 | 1 | 2 | 3 | Who believe in the Unseen, are steadfast in prayer, and ... | ????????? ??????????? ??????????? ???????????? ????????? ... | ????? ?????? ?????? ??????? ?????? ???? ??????? ?????? | 8 | 47 |
... (6226 rows omitted)
As you can see, we have the English translation under a column called “EnglishTranslation”, here is how to relabel the filed (which is the fourth one if you count from zero) to a shorter column name.
en = en.relabeled(4, 'en')
en
SrNo | JuzNo | SurahNo | AyahNo | en | OrignalArabicText | ArabicText | ArabicWordCount | ArabicLetterCount |
---|---|---|---|---|---|---|---|---|
1 | 1 | 1 | 1 | In the name of Allah, Most Gracious, Most Merciful. | ?????? ??????? ???????????? ?????????? | ??? ???? ?????? ?????? | 4 | 19 |
2 | 1 | 1 | 2 | Praise be to Allah, the Cherisher and Sustainer of the w ... | ????????? ??????? ????? ????????????? | ????? ??? ?? ???????? | 4 | 18 |
3 | 1 | 1 | 3 | Most Gracious, Most Merciful; | ???????????? ?????????? | ?????? ?????? | 2 | 12 |
4 | 1 | 1 | 4 | Master of the Day of Judgment. | ??????? ?????? ???????? | ???? ??? ????? | 3 | 12 |
5 | 1 | 1 | 5 | Thee do we worship, and Thine aid we seek. | ???????? ???????? ?????????? ??????????? | ???? ???? ????? ?????? | 4 | 19 |
6 | 1 | 1 | 6 | Show us the straight way, | ???????? ?????????? ?????????????? | ????? ?????? ???????? | 3 | 19 |
7 | 1 | 1 | 7 | The way of those on whom Thou hast bestowed Thy Grace, t ... | ??????? ????????? ?????????? ?????????? ?????? ????????? ... | ???? ????? ????? ????? ??? ??????? ????? ??? ??????? | 9 | 44 |
8 | 1 | 2 | 1 | A. L. M. | ??? | ??? | 1 | 3 |
9 | 1 | 2 | 2 | This is the Book; in it is guidance sure, without doubt, ... | ??????? ?????????? ??? ?????? ? ????? ? ????? ?????????????? | ??? ?????? ?? ??? ? ??? ? ???? ??????? | 9 | 30 |
10 | 1 | 2 | 3 | Who believe in the Unseen, are steadfast in prayer, and ... | ????????? ??????????? ??????????? ???????????? ????????? ... | ????? ?????? ?????? ??????? ?????? ???? ??????? ?????? | 8 | 47 |
... (6226 rows omitted)
en = en.select(['SrNo', 'en'])
en
SrNo | en |
---|---|
1 | In the name of Allah, Most Gracious, Most Merciful. |
2 | Praise be to Allah, the Cherisher and Sustainer of the w ... |
3 | Most Gracious, Most Merciful; |
4 | Master of the Day of Judgment. |
5 | Thee do we worship, and Thine aid we seek. |
6 | Show us the straight way, |
7 | The way of those on whom Thou hast bestowed Thy Grace, t ... |
8 | A. L. M. |
9 | This is the Book; in it is guidance sure, without doubt, ... |
10 | Who believe in the Unseen, are steadfast in prayer, and ... |
... (6226 rows omitted)
I have noticed a problem while checking the ‘SrNo’ of both datasets. The first dataset qwc
has SrNo starting from Zero, while the second en
starts from 1. So, let us create a new column sr
in the second dataset so we have similar ID value to join both tables.
en = en.with_columns('sr', en.column('SrNo')-1).drop('SrNo')
en
en | sr |
---|---|
In the name of Allah, Most Gracious, Most Merciful. | 0 |
Praise be to Allah, the Cherisher and Sustainer of the w ... | 1 |
Most Gracious, Most Merciful; | 2 |
Master of the Day of Judgment. | 3 |
Thee do we worship, and Thine aid we seek. | 4 |
Show us the straight way, | 5 |
The way of those on whom Thou hast bestowed Thy Grace, t ... | 6 |
A. L. M. | 7 |
This is the Book; in it is guidance sure, without doubt, ... | 8 |
Who believe in the Unseen, are steadfast in prayer, and ... | 9 |
... (6226 rows omitted)
en.row(en.num_rows-1)
Row(en='Among Jinns and among men.', sr=6235)
Everything seems in place. So, let us join. It works as follows:
Join the first table qwc
using the SrNo
as the ID with the corresponding table en
which has the same ID under column sr
. This will append all remaining columns of the second table en
to the new table which I chose to name it as quran
.
quran = qwc.join('SrNo', en, 'sr')
quran
SrNo | SurahNum | AyahNum | Ayah | words | en |
---|---|---|---|---|---|
0 | 1 | 1 | بسم الله الرحمن الرحيم | 4 | In the name of Allah, Most Gracious, Most Merciful. |
1 | 1 | 2 | الحمد لله رب العالمين | 4 | Praise be to Allah, the Cherisher and Sustainer of the w ... |
2 | 1 | 3 | الرحمن الرحيم | 2 | Most Gracious, Most Merciful; |
3 | 1 | 4 | مالك يوم الدين | 3 | Master of the Day of Judgment. |
4 | 1 | 5 | إياك نعبد وإياك نستعين | 4 | Thee do we worship, and Thine aid we seek. |
5 | 1 | 6 | اهدنا الصراط المستقيم | 3 | Show us the straight way, |
6 | 1 | 7 | صراط الذين أنعمت عليهم غير المغضوب عليهم ولا الضالين | 9 | The way of those on whom Thou hast bestowed Thy Grace, t ... |
7 | 2 | 1 | بسم الله الرحمن الرحيم الم | 5 | A. L. M. |
8 | 2 | 2 | ذلك الكتاب لا ريب فيه هدى للمتقين | 7 | This is the Book; in it is guidance sure, without doubt, ... |
9 | 2 | 3 | الذين يؤمنون بالغيب ويقيمون الصلاة ومما رزقناهم ينفقون | 8 | Who believe in the Unseen, are steadfast in prayer, and ... |
... (6226 rows omitted)
for convinience let us relable further some long fileds.
quran = quran.relabeled(1, 'sno').relabeled(2,'vno')
quran
SrNo | sno | vno | Ayah | words | en |
---|---|---|---|---|---|
0 | 1 | 1 | بسم الله الرحمن الرحيم | 4 | In the name of Allah, Most Gracious, Most Merciful. |
1 | 1 | 2 | الحمد لله رب العالمين | 4 | Praise be to Allah, the Cherisher and Sustainer of the w ... |
2 | 1 | 3 | الرحمن الرحيم | 2 | Most Gracious, Most Merciful; |
3 | 1 | 4 | مالك يوم الدين | 3 | Master of the Day of Judgment. |
4 | 1 | 5 | إياك نعبد وإياك نستعين | 4 | Thee do we worship, and Thine aid we seek. |
5 | 1 | 6 | اهدنا الصراط المستقيم | 3 | Show us the straight way, |
6 | 1 | 7 | صراط الذين أنعمت عليهم غير المغضوب عليهم ولا الضالين | 9 | The way of those on whom Thou hast bestowed Thy Grace, t ... |
7 | 2 | 1 | بسم الله الرحمن الرحيم الم | 5 | A. L. M. |
8 | 2 | 2 | ذلك الكتاب لا ريب فيه هدى للمتقين | 7 | This is the Book; in it is guidance sure, without doubt, ... |
9 | 2 | 3 | الذين يؤمنون بالغيب ويقيمون الصلاة ومما رزقناهم ينفقون | 8 | Who believe in the Unseen, are steadfast in prayer, and ... |
... (6226 rows omitted)
Display a verse
So, let us see how to find verse 2:255 in the quran?
quran.where('sno', 2).where('vno',255)
SrNo | sno | vno | Ayah | words | en |
---|---|---|---|---|---|
261 | 2 | 255 | الله لا إله إلا هو الحي القيوم لا تأخذه سنة ولا نوم له م ... | 50 | Allah! There is no god but He,-the Living, the Self-subs ... |
another example: find me first verses of all surahs.
quran.where('vno', 1)
SrNo | sno | vno | Ayah | words | en |
---|---|---|---|---|---|
0 | 1 | 1 | بسم الله الرحمن الرحيم | 4 | In the name of Allah, Most Gracious, Most Merciful. |
7 | 2 | 1 | بسم الله الرحمن الرحيم الم | 5 | A. L. M. |
293 | 3 | 1 | بسم الله الرحمن الرحيم الم | 5 | A. L. M. |
493 | 4 | 1 | بسم الله الرحمن الرحيم يا أيها الناس اتقوا ربكم الذي خلق ... | 33 | O mankind! reverence your Guardian-Lord, who created you ... |
669 | 5 | 1 | بسم الله الرحمن الرحيم يا أيها الذين آمنوا أوفوا بالعقود ... | 28 | O ye who believe! fulfil (all) obligations. Lawful unto ... |
789 | 6 | 1 | بسم الله الرحمن الرحيم الحمد لله الذي خلق السماوات والأر ... | 18 | Praise be Allah, Who created the heavens and the earth, ... |
954 | 7 | 1 | بسم الله الرحمن الرحيم المص | 5 | Alif, Lam, Mim, Sad. |
1160 | 8 | 1 | بسم الله الرحمن الرحيم يسألونك عن الأنفال قل الأنفال لله ... | 22 | They ask thee concerning (things taken as) spoils of war ... |
1235 | 9 | 1 | براءة من الله ورسوله إلى الذين عاهدتم من المشركين | 9 | A (declaration) of immunity from Allah and His Messenger ... |
1364 | 10 | 1 | بسم الله الرحمن الرحيم الر تلك آيات الكتاب الحكيم | 9 | A. L. R. These are the ayats of the Book of Wisdom. |
... (104 rows omitted)
Conditional selectivity
With the above example, we need to be mindful of the fact that the Arabic text in this dataset includes the bismillah
as the first part of the verse no. 1 of each surah, whereas the English translation does not do that. This have implications on the count of words.
So, let us adjust the words
count of the first verse of each surah by discounting 4 words (which is the count of words in Basmalah). But the last caviat is that we do not want to do this discounting on the first chapter of the Quran, because as we know the first verse of Sura Fatiha is a basmalah.
The same goes for Surah at-Tawbah which does not have the basmalah at the start, and hence it should not be discounted.
So, let us start defining a function that does that exactly.
def discount_basmalah(sura_no, verse_no, words):
if (sura_no==1 or sura_no==9):
return words
if (verse_no == 1):
return words-4
else:
return words
all it matters now is to apply that function to each row of the quran.
quran = quran.with_columns('wc', quran.apply(discount_basmalah,'sno','vno', 'words'))
quran
SrNo | sno | vno | Ayah | words | en | wc |
---|---|---|---|---|---|---|
0 | 1 | 1 | بسم الله الرحمن الرحيم | 4 | In the name of Allah, Most Gracious, Most Merciful. | 4 |
1 | 1 | 2 | الحمد لله رب العالمين | 4 | Praise be to Allah, the Cherisher and Sustainer of the w ... | 4 |
2 | 1 | 3 | الرحمن الرحيم | 2 | Most Gracious, Most Merciful; | 2 |
3 | 1 | 4 | مالك يوم الدين | 3 | Master of the Day of Judgment. | 3 |
4 | 1 | 5 | إياك نعبد وإياك نستعين | 4 | Thee do we worship, and Thine aid we seek. | 4 |
5 | 1 | 6 | اهدنا الصراط المستقيم | 3 | Show us the straight way, | 3 |
6 | 1 | 7 | صراط الذين أنعمت عليهم غير المغضوب عليهم ولا الضالين | 9 | The way of those on whom Thou hast bestowed Thy Grace, t ... | 9 |
7 | 2 | 1 | بسم الله الرحمن الرحيم الم | 5 | A. L. M. | 1 |
8 | 2 | 2 | ذلك الكتاب لا ريب فيه هدى للمتقين | 7 | This is the Book; in it is guidance sure, without doubt, ... | 7 |
9 | 2 | 3 | الذين يؤمنون بالغيب ويقيمون الصلاة ومما رزقناهم ينفقون | 8 | Who believe in the Unseen, are steadfast in prayer, and ... | 8 |
... (6226 rows omitted)
Makki or Madani
Let us bring in another interesting table about the place of revelation, i.e., Makki or Madani. I have brought in the data, so let us join it with out table.
q_place = Table.read_table('/kaggle/input/quran-makki-madani/quran-toc.csv')
q_place
No. | Name Arabic | Name | English Meaning | No of verses | Place | Chronology |
---|---|---|---|---|---|---|
1 | الفاتحة | Al-Fatiha | The Opening | 7 | Meccan | 5 |
2 | البقرة | Al-Baqara | The Cow | 286 | Medinan | 87 |
3 | آل عمران | Al Imran | The House of Joachim | 200 | Medinan | 89 |
4 | النساء | An-Nisa' | Women | 176 | Medinan | 92 |
5 | المائدة | Al-Ma'ida | The Table Spread | 120 | Medinan | 112 |
6 | الأنعام | Al-An'am | Cattle | 165 | Meccan | 55 |
7 | الأعراف | Al-A'raf | The Heights | 206 | Meccan | 39 |
8 | الأنفال | Al-Anfal | Spoils of War | 75 | Medinan | 88 |
9 | التوبة | At-Tawba | Repentance | 129 | Medinan | 113 |
10 | يونس | Yunus | Jonah | 109 | Meccan | 51 |
... (104 rows omitted)
Let us just select the two columns that interest us when it comes to joining.
q_select = q_place.select(['No.','Place'])
q_select
No. | Place |
---|---|
1 | Meccan |
2 | Medinan |
3 | Medinan |
4 | Medinan |
5 | Medinan |
6 | Meccan |
7 | Meccan |
8 | Medinan |
9 | Medinan |
10 | Meccan |
... (104 rows omitted)
Everything is ready, so let us do it.
quran = quran.join('sno',q_select,'No.')
quran
sno | SrNo | vno | Ayah | words | en | wc | Place |
---|---|---|---|---|---|---|---|
1 | 0 | 1 | بسم الله الرحمن الرحيم | 4 | In the name of Allah, Most Gracious, Most Merciful. | 4 | Meccan |
1 | 1 | 2 | الحمد لله رب العالمين | 4 | Praise be to Allah, the Cherisher and Sustainer of the w ... | 4 | Meccan |
1 | 2 | 3 | الرحمن الرحيم | 2 | Most Gracious, Most Merciful; | 2 | Meccan |
1 | 3 | 4 | مالك يوم الدين | 3 | Master of the Day of Judgment. | 3 | Meccan |
1 | 4 | 5 | إياك نعبد وإياك نستعين | 4 | Thee do we worship, and Thine aid we seek. | 4 | Meccan |
1 | 5 | 6 | اهدنا الصراط المستقيم | 3 | Show us the straight way, | 3 | Meccan |
1 | 6 | 7 | صراط الذين أنعمت عليهم غير المغضوب عليهم ولا الضالين | 9 | The way of those on whom Thou hast bestowed Thy Grace, t ... | 9 | Meccan |
2 | 7 | 1 | بسم الله الرحمن الرحيم الم | 5 | A. L. M. | 1 | Medinan |
2 | 8 | 2 | ذلك الكتاب لا ريب فيه هدى للمتقين | 7 | This is the Book; in it is guidance sure, without doubt, ... | 7 | Medinan |
2 | 9 | 3 | الذين يؤمنون بالغيب ويقيمون الصلاة ومما رزقناهم ينفقون | 8 | Who believe in the Unseen, are steadfast in prayer, and ... | 8 | Medinan |
... (6226 rows omitted)
we can run a quick analysis of the verse lengths, by using the sort
function.
quran.sort('wc', descending=True)
sno | SrNo | vno | Ayah | words | en | wc | Place |
---|---|---|---|---|---|---|---|
2 | 288 | 282 | يا أيها الذين آمنوا إذا تداينتم بدين إلى أجل مسمى فاكتبو ... | 129 | O ye who believe! When ye deal with each other, in trans ... | 129 | Medinan |
4 | 504 | 12 | ولكم نصف ما ترك أزواجكم إن لم يكن لهن ولد فإن كان لهن ول ... | 88 | In what your wives leave, your share is a half, if they ... | 88 | Medinan |
24 | 2821 | 31 | وقل للمؤمنات يغضضن من أبصارهن ويحفظن فروجهن ولا يبدين زي ... | 78 | And say to the believing women that they should lower th ... | 78 | Medinan |
73 | 5494 | 20 | إن ربك يعلم أنك تقوم أدنى من ثلثي الليل ونصفه وثلثه وطائ ... | 78 | Thy Lord doth know that thou standest forth (to prayer) ... | 78 | Meccan |
24 | 2851 | 61 | ليس على الأعمى حرج ولا على الأعرج حرج ولا على المريض حرج ... | 76 | It is no fault in the blind nor in one born lame, nor in ... | 76 | Medinan |
3 | 446 | 154 | ثم أنزل عليكم من بعد الغم أمنة نعاسا يغشى طائفة منكم وطا ... | 75 | After (the excitement) of the distress, He sent down cal ... | 75 | Medinan |
2 | 108 | 102 | واتبعوا ما تتلو الشياطين على ملك سليمان وما كفر سليمان و ... | 74 | They followed what the evil ones gave out (falsely) agai ... | 74 | Medinan |
2 | 202 | 196 | وأتموا الحج والعمرة لله فإن أحصرتم فما استيسر من الهدي و ... | 73 | And complete the Hajj or 'umra in the service of Allah. ... | 73 | Medinan |
4 | 503 | 11 | يوصيكم الله في أولادكم للذكر مثل حظ الأنثيين فإن كن نساء ... | 71 | Allah (thus) directs you as regards your Children's (Inh ... | 71 | Medinan |
22 | 2599 | 5 | يا أيها الناس إن كنتم في ريب من البعث فإنا خلقناكم من تر ... | 70 | O mankind! if ye have a doubt about the Resurrection, (c ... | 70 | Medinan |
... (6226 rows omitted)
The above tells us that Madani surahs are generally has bigger verse size, and that among the Meccan surahs the verse 20 or surah al-Muzzammil (sno. 73) is the largest among Meccan surah (and 4th largest in the Quran).
If we are interested to know the largest verses in only Meccan surah, then we apply the filter and then do the sort as follows.
quran.where('Place', 'Meccan').sort('wc', descending=True)
sno | SrNo | vno | Ayah | words | en | wc | Place |
---|---|---|---|---|---|---|---|
73 | 5494 | 20 | إن ربك يعلم أنك تقوم أدنى من ثلثي الليل ونصفه وثلثه وطائ ... | 78 | Thy Lord doth know that thou standest forth (to prayer) ... | 78 | Meccan |
74 | 5525 | 31 | وما جعلنا أصحاب النار إلا ملائكة وما جعلنا عدتهم إلا فتن ... | 57 | And We have set none but angels as Guardians of the Fire ... | 57 | Meccan |
6 | 881 | 93 | ومن أظلم ممن افترى على الله كذبا أو قال أوحي إلي ولم يوح ... | 49 | Who can be more wicked than one who inventeth a lie agai ... | 49 | Meccan |
12 | 1695 | 100 | ورفع أبويه على العرش وخروا له سجدا وقال يا أبت هذا تأويل ... | 47 | And he raised his parents high on the throne (of dignity ... | 47 | Meccan |
6 | 858 | 70 | وذر الذين اتخذوا دينهم لعبا ولهوا وغرتهم الحياة الدنيا و ... | 45 | Leave alone those who take their religion to be mere pla ... | 45 | Meccan |
46 | 4524 | 15 | ووصينا الإنسان بوالديه إحسانا حملته أمه كرها ووضعته كرها ... | 45 | We have enjoined on man kindness to his parents: In pain ... | 45 | Meccan |
6 | 879 | 91 | وما قدروا الله حق قدره إذ قالوا ما أنزل الله على بشر من ... | 44 | No just estimate of Allah do they make when they say: "N ... | 44 | Meccan |
6 | 887 | 99 | وهو الذي أنزل من السماء ماء فأخرجنا به نبات كل شيء فأخرج ... | 44 | It is He Who sendeth down rain from the skies: with it W ... | 44 | Meccan |
14 | 1771 | 22 | وقال الشيطان لما قضي الأمر إن الله وعدكم وعد الحق ووعدتك ... | 44 | And Satan will say when the matter is decided: "It was A ... | 44 | Meccan |
7 | 1110 | 157 | الذين يتبعون الرسول النبي الأمي الذي يجدونه مكتوبا عندهم ... | 43 | "Those who follow the messenger, the unlettered Prophet, ... | 43 | Meccan |
... (4603 rows omitted)
The words
column in the quran
table seems redundent, so we can drop it.
quran2 = quran.drop('words')
quran2
sno | SrNo | vno | Ayah | en | wc | Place |
---|---|---|---|---|---|---|
1 | 0 | 1 | بسم الله الرحمن الرحيم | In the name of Allah, Most Gracious, Most Merciful. | 4 | Meccan |
1 | 1 | 2 | الحمد لله رب العالمين | Praise be to Allah, the Cherisher and Sustainer of the w ... | 4 | Meccan |
1 | 2 | 3 | الرحمن الرحيم | Most Gracious, Most Merciful; | 2 | Meccan |
1 | 3 | 4 | مالك يوم الدين | Master of the Day of Judgment. | 3 | Meccan |
1 | 4 | 5 | إياك نعبد وإياك نستعين | Thee do we worship, and Thine aid we seek. | 4 | Meccan |
1 | 5 | 6 | اهدنا الصراط المستقيم | Show us the straight way, | 3 | Meccan |
1 | 6 | 7 | صراط الذين أنعمت عليهم غير المغضوب عليهم ولا الضالين | The way of those on whom Thou hast bestowed Thy Grace, t ... | 9 | Meccan |
2 | 7 | 1 | بسم الله الرحمن الرحيم الم | A. L. M. | 1 | Medinan |
2 | 8 | 2 | ذلك الكتاب لا ريب فيه هدى للمتقين | This is the Book; in it is guidance sure, without doubt, ... | 7 | Medinan |
2 | 9 | 3 | الذين يؤمنون بالغيب ويقيمون الصلاة ومما رزقناهم ينفقون | Who believe in the Unseen, are steadfast in prayer, and ... | 8 | Medinan |
... (6226 rows omitted)
With a small logic, we can have another column that counts the number of characters in each verse. The logic is that we can use len
function to count all characters in a verse which includes the whitespace which we can then discount by no. of words plus one. Let us do it.
lc = quran2.apply(len, 'Ayah')-quran2.column('wc')+1
quran2 = quran2.with_columns('lc', lc)
quran2
sno | SrNo | vno | Ayah | en | wc | Place | lc |
---|---|---|---|---|---|---|---|
1 | 0 | 1 | بسم الله الرحمن الرحيم | In the name of Allah, Most Gracious, Most Merciful. | 4 | Meccan | 19 |
1 | 1 | 2 | الحمد لله رب العالمين | Praise be to Allah, the Cherisher and Sustainer of the w ... | 4 | Meccan | 18 |
1 | 2 | 3 | الرحمن الرحيم | Most Gracious, Most Merciful; | 2 | Meccan | 12 |
1 | 3 | 4 | مالك يوم الدين | Master of the Day of Judgment. | 3 | Meccan | 12 |
1 | 4 | 5 | إياك نعبد وإياك نستعين | Thee do we worship, and Thine aid we seek. | 4 | Meccan | 19 |
1 | 5 | 6 | اهدنا الصراط المستقيم | Show us the straight way, | 3 | Meccan | 19 |
1 | 6 | 7 | صراط الذين أنعمت عليهم غير المغضوب عليهم ولا الضالين | The way of those on whom Thou hast bestowed Thy Grace, t ... | 9 | Meccan | 44 |
2 | 7 | 1 | بسم الله الرحمن الرحيم الم | A. L. M. | 1 | Medinan | 26 |
2 | 8 | 2 | ذلك الكتاب لا ريب فيه هدى للمتقين | This is the Book; in it is guidance sure, without doubt, ... | 7 | Medinan | 27 |
2 | 9 | 3 | الذين يؤمنون بالغيب ويقيمون الصلاة ومما رزقناهم ينفقون | Who believe in the Unseen, are steadfast in prayer, and ... | 8 | Medinan | 47 |
... (6226 rows omitted)
as previous, I am curious to know which verses has the most letters.
quran2.sort('lc', descending=True)
sno | SrNo | vno | Ayah | en | wc | Place | lc |
---|---|---|---|---|---|---|---|
2 | 288 | 282 | يا أيها الذين آمنوا إذا تداينتم بدين إلى أجل مسمى فاكتبو ... | O ye who believe! When ye deal with each other, in trans ... | 129 | Medinan | 551 |
24 | 2821 | 31 | وقل للمؤمنات يغضضن من أبصارهن ويحفظن فروجهن ولا يبدين زي ... | And say to the believing women that they should lower th ... | 78 | Medinan | 350 |
73 | 5494 | 20 | إن ربك يعلم أنك تقوم أدنى من ثلثي الليل ونصفه وثلثه وطائ ... | Thy Lord doth know that thou standest forth (to prayer) ... | 78 | Meccan | 329 |
24 | 2851 | 61 | ليس على الأعمى حرج ولا على الأعرج حرج ولا على المريض حرج ... | It is no fault in the blind nor in one born lame, nor in ... | 76 | Medinan | 315 |
2 | 108 | 102 | واتبعوا ما تتلو الشياطين على ملك سليمان وما كفر سليمان و ... | They followed what the evil ones gave out (falsely) agai ... | 74 | Medinan | 308 |
4 | 504 | 12 | ولكم نصف ما ترك أزواجكم إن لم يكن لهن ولد فإن كان لهن ول ... | In what your wives leave, your share is a half, if they ... | 88 | Medinan | 299 |
33 | 3585 | 53 | يا أيها الذين آمنوا لا تدخلوا بيوت النبي إلا أن يؤذن لكم ... | O ye who believe! Enter not the Prophet's houses,- until ... | 70 | Medinan | 294 |
3 | 446 | 154 | ثم أنزل عليكم من بعد الغم أمنة نعاسا يغشى طائفة منكم وطا ... | After (the excitement) of the distress, He sent down cal ... | 75 | Medinan | 291 |
2 | 202 | 196 | وأتموا الحج والعمرة لله فإن أحصرتم فما استيسر من الهدي و ... | And complete the Hajj or 'umra in the service of Allah. ... | 73 | Medinan | 290 |
2 | 239 | 233 | والوالدات يرضعن أولادهن حولين كاملين لمن أراد أن يتم الر ... | The mothers shall give such to their offspring for two w ... | 64 | Medinan | 288 |
... (6226 rows omitted)
Having the letter counts would enable lots more analysis on the stylistic properties of the Quran. For example, what is the average size of a single word in the Quran?
np.array(quran2.column('lc')).sum()/np.array(quran2.column('wc')).sum()
4.284034088718074
If we wanted to be a more detailed, we can repeat the same for Meccan and Medinan surahs.
qmeccan = quran2.where('Place','Meccan').select('wc','lc')
np.array(qmeccan.column('lc')).sum()/np.array(qmeccan.column('wc')).sum()
4.242243587052354
qmedinan = quran2.where('Place','Medinan').select('wc','lc')
np.array(qmedinan.column('lc')).sum()/np.array(qmedinan.column('wc')).sum()
4.350044762757386
It shows that on average, Quranic words are around 4.3 letters and that Medinan surahs has slighly bigger word size but not that much significant.
Saving the File
Above was just scratching the surface of what we can do with the Quranic dataset. I will leave the rest for you. Here, I am going to save the Quran Table as a csv file.
quran.to_csv('quran-en-ar-place.csv')
You can play and extend with the above notebook in the Kaggle site.