Skip to main content

Read z-Tree data files.

Project description

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 to install.

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.

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:

# 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:

# 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. 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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ztree2python-0.99.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ztree2python-0.99.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file ztree2python-0.99.2.tar.gz.

File metadata

  • Download URL: ztree2python-0.99.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for ztree2python-0.99.2.tar.gz
Algorithm Hash digest
SHA256 9c381f51d928c4c6c3bea361b56a500ed2a54fda11fbfbbb71e68541b4fde9cc
MD5 27edb98ec5c0cfe8fcdc2b9185ecf080
BLAKE2b-256 3279ce7fd48b7eaeba24efee4b93b255b6711730bcd3ef6d5778f432cefc1fa5

See more details on using hashes here.

File details

Details for the file ztree2python-0.99.2-py3-none-any.whl.

File metadata

  • Download URL: ztree2python-0.99.2-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for ztree2python-0.99.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6f05fbe657a695675c9e4c0728e7d7cf14fcf6d88d2a97fbc7e9c97eab4bc266
MD5 edb31c7f6479e27f247d707714bf40e0
BLAKE2b-256 197f81d638c2d43c6563a115d50525ee3bfb28f9b441bfbe53dc4a62a58d7036

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page