ztree2python


Nameztree2python JSON
Version 0.99.2 PyPI version JSON
download
home_pagehttps://github.com/takekan/ztree2python
SummaryRead z-Tree data files.
upload_time2023-02-02 18:48:04
maintainer
docs_urlNone
authorKan Takeuchi
requires_python
license
keywords z-tree z-tree ztree ztree ztree2python ztree2stata economic experiment experimental economics
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ztree2python

ztree2python imports a data file created by z-Tree (Fischbacher, 2007) into python as pandas dataframes.
This function inputs the "filename" of a z-Tree data file, and it returns a dictionary, which contains the dataframes of the tables.
The keys are the names of all tables, "globals", "subjects", and so on. The value associated with each key is a pandas dataframe for the table.

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install.

```bash
pip install ztree2python
```

Alternatively, simply put ztree2python.py and a z-Tree data file (e.g., 221215_1449.xls) in the current directory or the working directory. 

## Usage
The ztree2python is a simple function that takes the filename of a z-Tree data file as the argument and returns a dictionary that contains all of the tables in the z-Tree data file.
```python
from ztree2python import ztree2python as z2p

# input the file name, and it returns a dictionary.  
tables = z2p('221215_1449.xls')
```
The function returns a dictionary. Each table is stored as a dataframe in the ```tables```. Get the data of a table as follows:
```python
# Extract a table by name, for example, the "subjects" table.
my_table = tables['subjects']
my_table.head()
```
See all of the tables in ```tables``` as follows:
```python
# The dictionary also contains a series of table names. See the list.
tables['list_tables']

# Display all of the tables.
from IPython.display import display
for name, tbl in tables.items():
  display(tbl)
```

## Technical notes

The function reads the data and iterates the following process over the names of the tables. It filters the rows of the main dataframe to only include rows that belong to the current table. Then it processes the data for each treatment within the table and creates a dataframe for each treatment. 
If the period is repeated in the treatment, the data for the treatment has a header row with variable names inserted each period. This function assumes that these header rows are the same within the treatment and reads the top header row as the variable names, then removes all header rows afterwards. All data will be converted to numeric, if possible. Finally, the table for the current treatment is added to the dataframe for the current table. 

After all the tables have been processed, the function returns the dictionary of dataframes.

## License

[MIT](https://choosealicense.com/licenses/mit/). ztree2python is "provided "as is", without warranty of any kind."

## Reference
Fischbacher, U. (2007). z-Tree: Zurich toolbox for ready-made economic experiments. *Experimental Economics*, 10(2), 171-178. 
https://doi.org/10.1007/s10683-006-9159-4.

Takeuchi, Kan. (2022). ztree2python.py, http://github.com/takekan/ztree2python.

Takeuchi, K. (2022). ztree2stata: A data converter for z-Tree and Stata users. 

I would appreciate it if you kindly mention to this code in a footnote or somewhere.

Enjoy!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/takekan/ztree2python",
    "name": "ztree2python",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "z-Tree,z-tree,zTree,ztree,ztree2python,ztree2stata,economic experiment,experimental economics",
    "author": "Kan Takeuchi",
    "author_email": "takeuchi.kan@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/32/79/ce7fd48b7eaeba24efee4b93b255b6711730bcd3ef6d5778f432cefc1fa5/ztree2python-0.99.2.tar.gz",
    "platform": null,
    "description": "# ztree2python\r\n\r\nztree2python imports a data file created by z-Tree (Fischbacher, 2007) into python as pandas dataframes.\r\nThis function inputs the \"filename\" of a z-Tree data file, and it returns a dictionary, which contains the dataframes of the tables.\r\nThe keys are the names of all tables, \"globals\", \"subjects\", and so on. The value associated with each key is a pandas dataframe for the table.\r\n\r\n## Installation\r\n\r\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install.\r\n\r\n```bash\r\npip install ztree2python\r\n```\r\n\r\nAlternatively, simply put ztree2python.py and a z-Tree data file (e.g., 221215_1449.xls) in the current directory or the working directory. \r\n\r\n## Usage\r\nThe ztree2python is a simple function that takes the filename of a z-Tree data file as the argument and returns a dictionary that contains all of the tables in the z-Tree data file.\r\n```python\r\nfrom ztree2python import ztree2python as z2p\r\n\r\n# input the file name, and it returns a dictionary.  \r\ntables = z2p('221215_1449.xls')\r\n```\r\nThe function returns a dictionary. Each table is stored as a dataframe in the ```tables```. Get the data of a table as follows:\r\n```python\r\n# Extract a table by name, for example, the \"subjects\" table.\r\nmy_table = tables['subjects']\r\nmy_table.head()\r\n```\r\nSee all of the tables in ```tables``` as follows:\r\n```python\r\n# The dictionary also contains a series of table names. See the list.\r\ntables['list_tables']\r\n\r\n# Display all of the tables.\r\nfrom IPython.display import display\r\nfor name, tbl in tables.items():\r\n  display(tbl)\r\n```\r\n\r\n## Technical notes\r\n\r\nThe function reads the data and iterates the following process over the names of the tables. It filters the rows of the main dataframe to only include rows that belong to the current table. Then it processes the data for each treatment within the table and creates a dataframe for each treatment. \r\nIf the period is repeated in the treatment, the data for the treatment has a header row with variable names inserted each period. This function assumes that these header rows are the same within the treatment and reads the top header row as the variable names, then removes all header rows afterwards. All data will be converted to numeric, if possible. Finally, the table for the current treatment is added to the dataframe for the current table. \r\n\r\nAfter all the tables have been processed, the function returns the dictionary of dataframes.\r\n\r\n## License\r\n\r\n[MIT](https://choosealicense.com/licenses/mit/). ztree2python is \"provided \"as is\", without warranty of any kind.\"\r\n\r\n## Reference\r\nFischbacher, U. (2007). z-Tree: Zurich toolbox for ready-made economic experiments. *Experimental Economics*, 10(2), 171-178. \r\nhttps://doi.org/10.1007/s10683-006-9159-4.\r\n\r\nTakeuchi, Kan. (2022). ztree2python.py, http://github.com/takekan/ztree2python.\r\n\r\nTakeuchi, K. (2022). ztree2stata: A data converter for z-Tree and Stata users. \r\n\r\nI would appreciate it if you kindly mention to this code in a footnote or somewhere.\r\n\r\nEnjoy!\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Read z-Tree data files.",
    "version": "0.99.2",
    "split_keywords": [
        "z-tree",
        "z-tree",
        "ztree",
        "ztree",
        "ztree2python",
        "ztree2stata",
        "economic experiment",
        "experimental economics"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "197f81d638c2d43c6563a115d50525ee3bfb28f9b441bfbe53dc4a62a58d7036",
                "md5": "edb31c7f6479e27f247d707714bf40e0",
                "sha256": "6f05fbe657a695675c9e4c0728e7d7cf14fcf6d88d2a97fbc7e9c97eab4bc266"
            },
            "downloads": -1,
            "filename": "ztree2python-0.99.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "edb31c7f6479e27f247d707714bf40e0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6156,
            "upload_time": "2023-02-02T18:48:02",
            "upload_time_iso_8601": "2023-02-02T18:48:02.231089Z",
            "url": "https://files.pythonhosted.org/packages/19/7f/81d638c2d43c6563a115d50525ee3bfb28f9b441bfbe53dc4a62a58d7036/ztree2python-0.99.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3279ce7fd48b7eaeba24efee4b93b255b6711730bcd3ef6d5778f432cefc1fa5",
                "md5": "27edb98ec5c0cfe8fcdc2b9185ecf080",
                "sha256": "9c381f51d928c4c6c3bea361b56a500ed2a54fda11fbfbbb71e68541b4fde9cc"
            },
            "downloads": -1,
            "filename": "ztree2python-0.99.2.tar.gz",
            "has_sig": false,
            "md5_digest": "27edb98ec5c0cfe8fcdc2b9185ecf080",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5316,
            "upload_time": "2023-02-02T18:48:04",
            "upload_time_iso_8601": "2023-02-02T18:48:04.216526Z",
            "url": "https://files.pythonhosted.org/packages/32/79/ce7fd48b7eaeba24efee4b93b255b6711730bcd3ef6d5778f432cefc1fa5/ztree2python-0.99.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-02 18:48:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "takekan",
    "github_project": "ztree2python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ztree2python"
}
        
Elapsed time: 0.05880s