Commit 2d3e3a1a by Yolanda Nainggolan

storing multiple dictionary for displaying dataframe

parent b93842e7
...@@ -12,31 +12,9 @@ from Sastrawi.Stemmer.StemmerFactory import StemmerFactory ...@@ -12,31 +12,9 @@ from Sastrawi.Stemmer.StemmerFactory import StemmerFactory
from itertools import count from itertools import count
import collections import collections
import math import math
from xml.etree.ElementTree import ElementTree
import pandas as pd
from django.shortcuts import render
import xml.etree.ElementTree as et import xml.etree.ElementTree as et
def data_view(data):
df_cols = ["DOCNO", "SONG", "ARTIST", "LYRICS"]
rows = []
for node in data:
s_docno = node.find("DOCNO").text if node is not None else None
s_song = node.find("SONG").text if node is not None else None
s_artist = node.find("ARTIST").text if node is not None else None
s_lyrics = node.find("LYRICS").text if node is not None else None
rows.append({"DOCNO": s_docno, "SONG": s_song,
"ARTIST": s_artist, "LYRICS": s_lyrics})
DataFrame = pd.DataFrame(rows, columns = df_cols)
return render(data, 'apps/dataframe.html', {'DataFrame': DataFrame})
##############Remove Punctuation, URL and Tokenize################### ##############Remove Punctuation, URL and Tokenize###################
def remove_punc_tokenize(sentence): def remove_punc_tokenize(sentence):
tokens = [] tokens = []
...@@ -227,7 +205,7 @@ def main(query): ...@@ -227,7 +205,7 @@ def main(query):
return hasil return hasil
def detail(nomor): def detail(nomor):
tree = ElementTree() tree = et()
tree.parse("apps/data/dataset_STBI.xml") tree.parse("apps/data/dataset_STBI.xml")
all_doc_no = [] all_doc_no = []
......
...@@ -17,18 +17,21 @@ ...@@ -17,18 +17,21 @@
<center><h1>Dataset</h1><br> <center><h1>Dataset</h1><br>
<table style="width:100%"> <table style="width:100%">
<tr> <tr>
{% for data in DataFrame %} <th>DOCNO</th>
<th>{{ data }}</th> <th>SONG</th>
{% endfor %} <th>ARTIST</th>
<th>LYRICS</th>
{% for i, row in DataFrame.iterrows %}
<tr>
{% for value in data %}
<td>{{ value }}</td>
{% endfor %}
</tr>
{% endfor %}
</tr> </tr>
{% for l in LYRICS %}
<tr>
<td>{{ i }}</td>
<td>{{ j }}</td>
<td>{{ k }}</td>
<td>{{ l }}</td>
</tr>
{% endfor %}
</table> </table>
</center> </center>
</article> </article>
...@@ -36,9 +39,9 @@ ...@@ -36,9 +39,9 @@
</main> </main>
<footer> <!-- <footer>
<p>&copy; STBI-2020-03</p> <p>&copy; STBI-2020-03</p>
</footer> </footer> -->
</body> </body>
......
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from InvertedIndexSimulator.inverted import main from InvertedIndexSimulator.inverted import main
# Create your views here. import pandas as pd
# def index(request): import xml.etree.ElementTree as et
# return HttpResponse("Hello, world. You're at the polls index.")
def home(request): def home(request):
return render(request, 'apps/home.html') return render(request, 'apps/home.html')
def dataframe(request): def dataframe(request):
import pandas as pd
import xml.etree.ElementTree as et
parse_data = et.parse("InvertedIndexSimulator/data/dataset_STBI.xml") parse_data = et.parse("InvertedIndexSimulator/data/dataset_STBI.xml")
data = parse_data.getroot() data = parse_data.getroot()
content = main.data_view(data)
return render(request, 'apps/dataframe.html', content) df_cols = ["DOCNO", "SONG", "ARTIST", "LYRICS"]
rows = []
for node in data:
s_docno = node.find("DOCNO").text if node is not None else None
s_song = node.find("SONG").text if node is not None else None
s_artist = node.find("ARTIST").text if node is not None else None
s_lyrics = node.find("LYRICS").text if node is not None else None
rows.append({"DOCNO": s_docno, "SONG": s_song, "ARTIST": s_artist, "LYRICS": s_lyrics})
DataFrame = pd.DataFrame(rows, columns = df_cols)
dictionary = DataFrame.set_index('DOCNO').T.to_dict('list')
nilai = list(dictionary.values())
nomornya = list(dictionary.keys())
lagunya = [sublist[0] for sublist in nilai]
artisnya = [sublist[1] for sublist in nilai]
liriknya = [sublist[2] for sublist in nilai]
context = {"DOCNO": nomornya, "SONG": lagunya, "ARTIST": artisnya, "LYRICS": liriknya}
return render(request, 'apps/dataframe.html', context)
def preprocessing(request): def preprocessing(request):
return render(request, 'apps/preprocessing.html') return render(request, 'apps/preprocessing.html')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment