32 lines
928 B
Python
32 lines
928 B
Python
import json
|
|
import pandas as pd
|
|
|
|
# Wczytanie danych JSON z pliku
|
|
with open('2dane.json', 'r', encoding='utf-8') as file:
|
|
data = json.load(file)
|
|
|
|
# Przygotowanie danych do tabeli
|
|
rows = []
|
|
for category in data['categories']:
|
|
for keyword in category['keywords']:
|
|
for source in keyword['top_sources']:
|
|
rows.append({
|
|
'Category': category['category'],
|
|
'CategorySummary': category['category_summary'],
|
|
'Keyword': keyword['keyword'],
|
|
'Summary': keyword['summary'],
|
|
'Trending': keyword['trending'],
|
|
'Source': source['source'],
|
|
'Text': source['text'],
|
|
'URL': source['url']
|
|
})
|
|
|
|
# Konwersja na DataFrame Pandas
|
|
df = pd.DataFrame(rows)
|
|
|
|
# Wyświetlenie tabeli
|
|
print(df)
|
|
|
|
# Zapisanie tabeli do pliku CSV (opcjonalnie)
|
|
df.to_csv('tabela.csv', index=False, encoding='utf-8')
|