Last active
December 20, 2015 03:58
-
-
Save brentp/6066942 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from StringIO import StringIO | |
import numpy as np | |
import re | |
import string | |
txt = """\ | |
a b c d e f g h i | |
0 0 1 0 0 1 0 0 0 | |
1 0 0 0 0 0 0 0 0 | |
1 0 0 1 0 1 0 1 0 | |
0 0 0 1 0 1 0 1 0 | |
1 0 1 1 0 0 0 0 0 | |
0 0 0 0 0 1 0 0 0 | |
1 0 1 1 0 0 0 0 0 | |
1 0 1 1 0 0 0 0 1 | |
1 0 1 1 0 1 0 0 1""" | |
df = pd.read_csv(StringIO(txt), dtype=np.int_, sep="\s+") | |
df.index = [string.letters[i] for i in range(len(df))] | |
print "original:", df.shape | |
df.to_csv('t.txt', sep="\t") | |
df = pd.read_csv('t.txt', dtype=np.int_, sep="\s+", index_col=0) | |
print "OK \s+", df.shape | |
# with index_col, and sep of "\t" get an error about dtype. | |
df = pd.read_csv('t.txt', dtype=np.int_, sep="\t", index_col=0) | |
print "OK \t" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a b c d e f g h i | |
a 0 0 1 0 0 1 0 0 0 | |
b 1 0 0 0 0 0 0 0 0 | |
c 1 0 0 1 0 1 0 1 0 | |
d 0 0 0 1 0 1 0 1 0 | |
e 1 0 1 1 0 0 0 0 0 | |
f 0 0 0 0 0 1 0 0 0 | |
g 1 0 1 1 0 0 0 0 0 | |
h 1 0 1 1 0 0 0 0 1 | |
i 1 0 1 1 0 1 0 0 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment