How to save a pandas dataframe such that there is no delimiter?
<p>I have the following pandas dataframe:</p>

<pre><code>import pandas as pd
df = pd.DataFrame(np.random.choice([0,1], (6,3)), columns=list('XYZ'))

   X  Y  Z
0  1  0  1
1  1  1  0
2  0  0  0
3  0  1  1
4  0  1  1
5  1  1  1
</code></pre>

<p>Let's say I take the transpose and wish to save it</p>

<pre><code>df = df.T

   0  1  2  3  4  5
X  1  1  0  0  0  1
Y  0  1  0  1  1  1
Z  1  0  0  1  1  1
</code></pre>

<p>So, there three rows. I would like to save it in this format:</p>

<pre><code>X  110001
Y  010111
Z  100111
</code></pre>

<p>I tried </p>

<pre><code>df.to_csv("filename.txt", header=None, index=None, sep='')
</code></pre>

<p>However, this outputs an error: </p>

<pre><code>TypeError: "delimiter" must be an 1-character string
</code></pre>

<p>Is it possible to save the dataframe in this manner, or is there some what to combine all columns into one? What is the most "pandas" solution?</p>

<p>Leave original <code>df</code> alone.  Don't transpose.</p>

<pre><code>df = pd.DataFrame(np.random.choice([0,1], (6,3)), columns=list('XYZ'))

df.astype(str).apply(''.join)

X    101100
Y    101001
Z    111110
dtype: object
</code></pre>

python csv pandas dataframe