11 KiB
11 KiB
# librarys:
import json
import csv
import os
import pandas as pd
# data extraction function
#
# input - file with events
# output - file with only goals events
# unfinished
def goals_extraction(file):
return file
# os path
#path = Path('data','la_liga_events','7298.json')
def openGameFile(name):
path = os.path.join("..","data","la_liga_events",name)
f = open(path)
data = json.load(f)
return data
name = "7298.json"
jsonFile = openGameFile(name)
csvFilePath = os.path.join("..","data","la_liga_events_csv","test.csv")
csvFile = open(csvFilePath, 'w', newline='')
csv_writer = csv.writer(csvFile)
count = 0
for data in jsonFile:
if count == 0:
header = data.keys()
csv_writer.writerow(header)
count += 1
csv_writer.writerow(data.values())
df_temp = pd.read_csv(csvFile, index_col=None, header=0)
csvFile.close()
df_temp
[1;31m---------------------------------------------------------------------------[0m [1;31mUnsupportedOperation[0m Traceback (most recent call last) [1;32mc:\Users\MSi\Desktop\data_repo\fantastyczne_gole\notebooks\dataExtraction.ipynb Cell 4[0m line [0;36m3 [0;32m <a href='vscode-notebook-cell:/c%3A/Users/MSi/Desktop/data_repo/fantastyczne_gole/notebooks/dataExtraction.ipynb#W2sZmlsZQ%3D%3D?line=28'>29</a>[0m count [39m+[39m[39m=[39m [39m1[39m [0;32m <a href='vscode-notebook-cell:/c%3A/Users/MSi/Desktop/data_repo/fantastyczne_gole/notebooks/dataExtraction.ipynb#W2sZmlsZQ%3D%3D?line=29'>30</a>[0m csv_writer[39m.[39mwriterow(data[39m.[39mvalues()) [1;32m---> <a href='vscode-notebook-cell:/c%3A/Users/MSi/Desktop/data_repo/fantastyczne_gole/notebooks/dataExtraction.ipynb#W2sZmlsZQ%3D%3D?line=31'>32</a>[0m df_temp [39m=[39m pd[39m.[39;49mread_csv(csvFile, index_col[39m=[39;49m[39mNone[39;49;00m, header[39m=[39;49m[39m0[39;49m) [0;32m <a href='vscode-notebook-cell:/c%3A/Users/MSi/Desktop/data_repo/fantastyczne_gole/notebooks/dataExtraction.ipynb#W2sZmlsZQ%3D%3D?line=32'>33</a>[0m csvFile[39m.[39mclose() [0;32m <a href='vscode-notebook-cell:/c%3A/Users/MSi/Desktop/data_repo/fantastyczne_gole/notebooks/dataExtraction.ipynb#W2sZmlsZQ%3D%3D?line=34'>35</a>[0m df_temp File [1;32m~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\parsers\readers.py:912[0m, in [0;36mread_csv[1;34m(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, date_format, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options, dtype_backend)[0m [0;32m 899[0m kwds_defaults [39m=[39m _refine_defaults_read( [0;32m 900[0m dialect, [0;32m 901[0m delimiter, [1;32m (...)[0m [0;32m 908[0m dtype_backend[39m=[39mdtype_backend, [0;32m 909[0m ) [0;32m 910[0m kwds[39m.[39mupdate(kwds_defaults) [1;32m--> 912[0m [39mreturn[39;00m _read(filepath_or_buffer, kwds) File [1;32m~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\parsers\readers.py:577[0m, in [0;36m_read[1;34m(filepath_or_buffer, kwds)[0m [0;32m 574[0m _validate_names(kwds[39m.[39mget([39m"[39m[39mnames[39m[39m"[39m, [39mNone[39;00m)) [0;32m 576[0m [39m# Create the parser.[39;00m [1;32m--> 577[0m parser [39m=[39m TextFileReader(filepath_or_buffer, [39m*[39m[39m*[39mkwds) [0;32m 579[0m [39mif[39;00m chunksize [39mor[39;00m iterator: [0;32m 580[0m [39mreturn[39;00m parser File [1;32m~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\parsers\readers.py:1407[0m, in [0;36mTextFileReader.__init__[1;34m(self, f, engine, **kwds)[0m [0;32m 1404[0m [39mself[39m[39m.[39moptions[[39m"[39m[39mhas_index_names[39m[39m"[39m] [39m=[39m kwds[[39m"[39m[39mhas_index_names[39m[39m"[39m] [0;32m 1406[0m [39mself[39m[39m.[39mhandles: IOHandles [39m|[39m [39mNone[39;00m [39m=[39m [39mNone[39;00m [1;32m-> 1407[0m [39mself[39m[39m.[39m_engine [39m=[39m [39mself[39;49m[39m.[39;49m_make_engine(f, [39mself[39;49m[39m.[39;49mengine) File [1;32m~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\parsers\readers.py:1679[0m, in [0;36mTextFileReader._make_engine[1;34m(self, f, engine)[0m [0;32m 1676[0m [39mraise[39;00m [39mValueError[39;00m(msg) [0;32m 1678[0m [39mtry[39;00m: [1;32m-> 1679[0m [39mreturn[39;00m mapping[engine](f, [39m*[39m[39m*[39m[39mself[39m[39m.[39moptions) [0;32m 1680[0m [39mexcept[39;00m [39mException[39;00m: [0;32m 1681[0m [39mif[39;00m [39mself[39m[39m.[39mhandles [39mis[39;00m [39mnot[39;00m [39mNone[39;00m: File [1;32m~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\parsers\c_parser_wrapper.py:93[0m, in [0;36mCParserWrapper.__init__[1;34m(self, src, **kwds)[0m [0;32m 90[0m [39mif[39;00m kwds[[39m"[39m[39mdtype_backend[39m[39m"[39m] [39m==[39m [39m"[39m[39mpyarrow[39m[39m"[39m: [0;32m 91[0m [39m# Fail here loudly instead of in cython after reading[39;00m [0;32m 92[0m import_optional_dependency([39m"[39m[39mpyarrow[39m[39m"[39m) [1;32m---> 93[0m [39mself[39m[39m.[39m_reader [39m=[39m parsers[39m.[39mTextReader(src, [39m*[39m[39m*[39mkwds) [0;32m 95[0m [39mself[39m[39m.[39munnamed_cols [39m=[39m [39mself[39m[39m.[39m_reader[39m.[39munnamed_cols [0;32m 97[0m [39m# error: Cannot determine type of 'names'[39;00m File [1;32m~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\_libs\parsers.pyx:548[0m, in [0;36mpandas._libs.parsers.TextReader.__cinit__[1;34m()[0m File [1;32m~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\_libs\parsers.pyx:637[0m, in [0;36mpandas._libs.parsers.TextReader._get_header[1;34m()[0m File [1;32m~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\_libs\parsers.pyx:848[0m, in [0;36mpandas._libs.parsers.TextReader._tokenize_rows[1;34m()[0m File [1;32m~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\_libs\parsers.pyx:859[0m, in [0;36mpandas._libs.parsers.TextReader._check_tokenize_status[1;34m()[0m File [1;32m~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\_libs\parsers.pyx:2014[0m, in [0;36mpandas._libs.parsers.raise_parser_error[1;34m()[0m [1;31mUnsupportedOperation[0m: not readable