Commit 2d3e3a1a by Yolanda Nainggolan

storing multiple dictionary for displaying dataframe

parent b93842e7
......@@ -12,31 +12,9 @@ from Sastrawi.Stemmer.StemmerFactory import StemmerFactory
from itertools import count
import collections
import math
from xml.etree.ElementTree import ElementTree
import pandas as pd
from django.shortcuts import render
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###################
def remove_punc_tokenize(sentence):
tokens = []
......@@ -227,7 +205,7 @@ def main(query):
return hasil
def detail(nomor):
tree = ElementTree()
tree = et()
tree.parse("apps/data/dataset_STBI.xml")
all_doc_no = []
......
......@@ -17,18 +17,21 @@
<center><h1>Dataset</h1><br>
<table style="width:100%">
<tr>
{% for data in DataFrame %}
<th>{{ data }}</th>
{% endfor %}
{% for i, row in DataFrame.iterrows %}
<tr>
{% for value in data %}
<td>{{ value }}</td>
{% endfor %}
</tr>
{% endfor %}
<th>DOCNO</th>
<th>SONG</th>
<th>ARTIST</th>
<th>LYRICS</th>
</tr>
{% for l in LYRICS %}
<tr>
<td>{{ i }}</td>
<td>{{ j }}</td>
<td>{{ k }}</td>
<td>{{ l }}</td>
</tr>
{% endfor %}
</table>
</center>
</article>
......@@ -36,9 +39,9 @@
</main>
<footer>
<!-- <footer>
<p>&copy; STBI-2020-03</p>
</footer>
</footer> -->
</body>
......
from django.shortcuts import render
from django.http import HttpResponse
from InvertedIndexSimulator.inverted import main
# Create your views here.
# def index(request):
# return HttpResponse("Hello, world. You're at the polls index.")
import pandas as pd
import xml.etree.ElementTree as et
def home(request):
return render(request, 'apps/home.html')
def dataframe(request):
import pandas as pd
import xml.etree.ElementTree as et
parse_data = et.parse("InvertedIndexSimulator/data/dataset_STBI.xml")
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):
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