fantastyczne_gole/notebooks/dataExtraction.ipynb

11 KiB
Raw Blame History

# 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
---------------------------------------------------------------------------
UnsupportedOperation                      Traceback (most recent call last)
c:\Users\MSi\Desktop\data_repo\fantastyczne_gole\notebooks\dataExtraction.ipynb Cell 4 line 3
     <a href='vscode-notebook-cell:/c%3A/Users/MSi/Desktop/data_repo/fantastyczne_gole/notebooks/dataExtraction.ipynb#W2sZmlsZQ%3D%3D?line=28'>29</a>         count += 1
     <a href='vscode-notebook-cell:/c%3A/Users/MSi/Desktop/data_repo/fantastyczne_gole/notebooks/dataExtraction.ipynb#W2sZmlsZQ%3D%3D?line=29'>30</a>     csv_writer.writerow(data.values())
---> <a href='vscode-notebook-cell:/c%3A/Users/MSi/Desktop/data_repo/fantastyczne_gole/notebooks/dataExtraction.ipynb#W2sZmlsZQ%3D%3D?line=31'>32</a> df_temp = pd.read_csv(csvFile, index_col=None, header=0)
     <a href='vscode-notebook-cell:/c%3A/Users/MSi/Desktop/data_repo/fantastyczne_gole/notebooks/dataExtraction.ipynb#W2sZmlsZQ%3D%3D?line=32'>33</a> csvFile.close()
     <a href='vscode-notebook-cell:/c%3A/Users/MSi/Desktop/data_repo/fantastyczne_gole/notebooks/dataExtraction.ipynb#W2sZmlsZQ%3D%3D?line=34'>35</a> df_temp

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\parsers\readers.py:912, in read_csv(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)
    899 kwds_defaults = _refine_defaults_read(
    900     dialect,
    901     delimiter,
   (...)
    908     dtype_backend=dtype_backend,
    909 )
    910 kwds.update(kwds_defaults)
--> 912 return _read(filepath_or_buffer, kwds)

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\parsers\readers.py:577, in _read(filepath_or_buffer, kwds)
    574 _validate_names(kwds.get("names", None))
    576 # Create the parser.
--> 577 parser = TextFileReader(filepath_or_buffer, **kwds)
    579 if chunksize or iterator:
    580     return parser

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\parsers\readers.py:1407, in TextFileReader.__init__(self, f, engine, **kwds)
   1404     self.options["has_index_names"] = kwds["has_index_names"]
   1406 self.handles: IOHandles | None = None
-> 1407 self._engine = self._make_engine(f, self.engine)

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\parsers\readers.py:1679, in TextFileReader._make_engine(self, f, engine)
   1676     raise ValueError(msg)
   1678 try:
-> 1679     return mapping[engine](f, **self.options)
   1680 except Exception:
   1681     if self.handles is not None:

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\parsers\c_parser_wrapper.py:93, in CParserWrapper.__init__(self, src, **kwds)
     90 if kwds["dtype_backend"] == "pyarrow":
     91     # Fail here loudly instead of in cython after reading
     92     import_optional_dependency("pyarrow")
---> 93 self._reader = parsers.TextReader(src, **kwds)
     95 self.unnamed_cols = self._reader.unnamed_cols
     97 # error: Cannot determine type of 'names'

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\_libs\parsers.pyx:548, in pandas._libs.parsers.TextReader.__cinit__()

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\_libs\parsers.pyx:637, in pandas._libs.parsers.TextReader._get_header()

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\_libs\parsers.pyx:848, in pandas._libs.parsers.TextReader._tokenize_rows()

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\_libs\parsers.pyx:859, in pandas._libs.parsers.TextReader._check_tokenize_status()

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\_libs\parsers.pyx:2014, in pandas._libs.parsers.raise_parser_error()

UnsupportedOperation: not readable