私はコーディングが新しく、扱う大きなデータがたくさんあります。現在、私は26個のtsv
ファイルをマージしようとしています(それぞれは、一方が他方のカウントであるcontig _number
で、ヘッダなしで2つの列があります。あまりにも多くのメモリを使用するpandas '外側'の複数のcsvsのマージ
tsv
は、特定のcontig_number
のカウントを持っていなかった場合は、それがあることはありません。私は最初のテストを実行するためにサブセット化したが、私はスクリプトを実行するときに成功しました。実際のデータは大きい(〜40,000行、2列)、より多くのメモリが使用されます...
サーバ上で500GbのRAMを使用し、それを1日と呼びました。
これはサブセットCSVを上成功しているコードです:
files = glob.glob('*_count.tsv')
data_frames = []
logging.info("Reading in sample files and adding to list")
for fp in files:
# read in the files and put them into dataframes
df = pd.read_csv(fp, sep = '\t', header = None, index_col = 0)
# rename the columns so we know what file they came from
df = df.rename(columns = {1:str(fp)}).reset_index()
df = df.rename(columns = {0:"contig"})
# append the dataframes to a list
data_frames.append(df)
logging.info("Merging the tables on contig, and fill in samples with no counts for contigs")
# merge the tables on gene_id and select how = 'outer' which will include all rows but will leave empty space where there is no data
df=reduce(lambda left,right: pd.merge(left, right, how='outer', on="contig"), data_frames)
# this bit is important to fill missing data with a 0
df.fillna(0, inplace = True)
logging.info("Writing concatenated count table to file")
# write the dataframe to file
df.to_csv("combined_bamm_filter_count_file.tsv",
sep='\t', index=False, header=True)
私が何かアドバイスや提案をいただければ幸いです!たぶんあまりにも多くのメモリを保持するだけで、私は別の何かをしようとする必要があります。
ありがとうございました!
こんにちはビクター、ありがとうございます! pd.concatを試行する過程で、ファイルのいくつかが誤って解析され、重複したインデックスがあることに気付きました。私はそれを修正し、concat正しい道を与える! – Caitlin