質問

私は数千の列と1万の行を持つCSVからのデータを持っています。各列内では、データは同じタイプのものですが、異なる列には異なるタイプ*のデータがあります。以前に私はNumpyからデータをピックしてディスクに保存していますが、特に通常遅く、通常は列のサブセットをロードしたいと思います。

Pyteablesを使用してデータをHDF5に入れたいと思うため、CSV列ごとに1つのHDF5列でデータを単一のテーブルに入れることでした。残念ながらこれはうまくいきませんでした、私は512(柔らかい)列の限界のために仮定します。

このデータを保存する賢明な方法は何ですか?

* iの意味で、テキストから変換された後のデータの種類。

役に立ちましたか?

解決

これは実際には、素朴な方法ですることが可能ではないかもしれません。HDF5は、すべてのデータセットのメタデータに対して64 KBのスペースを割り当てます。このメタデータには、列の種類が含まれています。したがって、列数はソフトリミットで、2~3000の範囲のどこかに、通常はスペースが不足してメタデータを保存します(列名の長さなどに応じて)。

さらに、列数を32に制限しませんか?今すぐnumpyでデータをどのように表現していますか?numpy配列に入ることができるものは、Pytablesアレイクラスに対応しています。

他のヒント

Petterables、 H5PY 代わりに、これは機能する可能性があります。

data = np.recfromcsv(args[0], delimiter=',',
                     case_sensitive=True, deletechars='', replace_space=' ')
with h5py.File(args[1], 'w') as h5file:
    h5file.create_dataset('table', data=data)
.

私はこの回答;

私は最初の行を借りました。それがあなたのために機能するかどうかわからない。 HDF 5テーブルは罰金(HDFViewのクイックルックから)微調整です。もちろん、PANDASとPandasで使用できるかどうかわかりません。

Perhaps you can increase the number columns without much performance degradation. See: http://www.pytables.org/docs/manual-2.2.1/apc.html

C.1.1. Recommended maximum values

MAX_COLUMNS

Maximum number of columns in Table objects before a PerformanceWarning is issued. This limit is somewhat arbitrary and can be increased.

If you want to go this route, simply find the parameters.py file in pytables directory and change the MAX_COLUMNS value.

you should be able to use pandas dataframe it can be saved to disk without converting to csv

IMHO it depends on what do you want to do with the data afterwards and how much of it do you need at one time. I had to build a program for statistical validation a while ago and we had two approaches:

  1. Split the columns in separate tables (e.g. using a FK). The overhead of loading them is not too high
  2. Transpose the table, resulting in something like a key-value store, where the key is a tuple of (column, row)

For both we used postgres.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top