0

I have a data.frame a with 5 columns and 2000 rows and a data.frame b with 200 columns and 10,000,000 rows. I am trying to merge these 2 data frames based on two common columns using the following code:

import pandas as pd
pd.set_option('expand_frame_repr', False)

import sys
sys.stdout = open("c.txt", "w")

ct = pd.read_csv("a.txt", sep = ",")
gtex = pd.read_csv("b.txt", sep = "\t")

s1 = pd.merge(ct, gtex, how='left', on=['CHR', 'POS'])

print s1

However, what I get as c.txt is something like this (toy example):

A B C ... X Y Z
1 4 5 ... 1 1 1
2 6 7 ... 3 3 3
...   ... .....
1999 6 7 ... 6 7 8
2000 8 9 ... 8 9 9

I would like to obtain a c.txt file displaying all 203 columns and 2000 rows but I am not able to do it.

I have an Apple laptop and I am using Python 2.7. I have seen posts like Python pandas, how to widen output display to see more columns? and tried options like this:

pd.set_option('display.max_columns', None)
pd.set_option('max_rows',3000)
pd.set_option('max_colwidth', 200)
pd.set_option('display.height', 1000)
pd.set_option('display.max_columns', 150)
pd.set_option('display.width', 1000)

But nothing is giving me the desired output. Please help

Lucas
  • 1,139
  • 3
  • 11
  • 23

1 Answers1

2

Pandas abbreviates DataFrames when printing to the console. Instead, use DataFrame.to_csv to write the DataFrame directly to a file.

See here for information about to_csv.

For example:

s1.to_csv('data.csv')
FamousJameous
  • 1,565
  • 11
  • 25