Closed shashicstl closed 9 years ago
The QTable
class extends numpy.recarray
, so you can use numpy.savetxt
to save it as a CSV:
np = q('flip `name`iq!(`Dent`Beeblebrox`Prefect;98 42 126)')
numpy.savetxt('np.csv', np, delimiter = ',', header = ','.join(np.dtype.names), fmt = '%s')
Or if you prefer to represent tables as pandas DataFrame
s, use pandas.DataFrame.to_csv
:
df = q('flip `name`iq!(`Dent`Beeblebrox`Prefect;98 42 126)', pandas = True)
df.to_csv('df.csv', sep = ',')
Awesome thank you. New to qpython, numpy and pandas.
I was able to test dumping to csv using pandas df. Works, however I see that timestammps have '0 days' in them, eg: 0 days 05:01:12.965000000
I'd like to get rid of '0 days' part and print up to milliseconds.
Can you point me to doc that let's me how to format etc?
You can refer to this stackoverflow post: http://stackoverflow.com/questions/13999850/how-to-specify-date-format-when-using-pandas-to-csv
Thank you.
Appreciate help.
Hello,
I am trying to use qpython for the first time. One of my use cases is to run a query and dump data to csv file. Is there an easy way to do so? I can write individual rows, but how do I get column names.
Many thanks.