Skip to content

Instantly share code, notes, and snippets.

@jazzyjackson
Created March 11, 2020 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jazzyjackson/dfeb861720f44a334878119c72ae89ed to your computer and use it in GitHub Desktop.
Save jazzyjackson/dfeb861720f44a334878119c72ae89ed to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# must be run with pyvalidate in PYTHONPATH
# condavision uses PYTHONPATH to check dependencies
import pandas,numpy
import StringIO, time
import pyvalidate
valid = pyvalidate.parameters({
"rows": {
"type":"number::int",
"info":"number of rows",
"placeholder":"for example: 3",
"verify":"^\d+$"
},
"cols": {
"type":"number::int",
"info":"number of columns",
"placeholder":"for example: 5",
"verify":"^\d+$"
},
"file": {
"info": "Where should the result be saved?",
"type": "text::buffer",
"value": 'example' + str(int(time.time())) + '.csv',
"verify": "^[A-Za-z0-9.-]+$" # restrict filename if you want
},
"labels": {
"type":"text::bool",
"info":"Whether to print row and column labels",
"verify":"(?i)^(true|false)$",
"placeholder": "True or False"
}
})
# Guassian distribution
samples = pandas.DataFrame(numpy.random.rand(valid.rows, valid.cols))
print(samples)
valid.file.write(samples.to_csv(
index=valid.get('labels', False),
header=valid.get('labels', False),
))
valid.file.close()
valid.output({'download': valid.file.name })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment