from_string¶
In [14]:
import pandas as pd
import numpy as np
import io
def from_string(_str, **kwargs):
# http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.from_csv.html
return pd.DataFrame.from_csv(io.StringIO(_str), **kwargs)
_csv = """a,b,c
1,2,3
4,5,6
"""
In [4]:
from_string(_csv)
Out[4]:
b | c | |
---|---|---|
a | ||
1 | 2 | 3 |
4 | 5 | 6 |
In [5]:
from_string(_csv, index_col=None)
Out[5]:
a | b | c | |
---|---|---|---|
0 | 1 | 2 | 3 |
1 | 4 | 5 | 6 |
In [6]:
from_string(_csv[1:])
Out[6]:
b | c | |
---|---|---|
1 | 2 | 3 |
4 | 5 | 6 |
In [7]:
pd.read_csv(io.StringIO(_csv))
Out[7]:
a | b | c | |
---|---|---|---|
0 | 1 | 2 | 3 |
1 | 4 | 5 | 6 |
In [9]:
import pyperclip
def from_clipboad(**kwargs):
return from_string(pyperclip.paste(), **kwargs)
In [11]:
pyperclip.copy(_csv)
from_clipboad(index_col=None)
Out[11]:
a | b | c | |
---|---|---|---|
0 | 1 | 2 | 3 |
1 | 4 | 5 | 6 |
In [12]:
pyperclip.copy(_csv)
pd.read_clipboard(sep=",")
Out[12]:
a | b | c | |
---|---|---|---|
0 | 1 | 2 | 3 |
1 | 4 | 5 | 6 |
In [15]:
import string
df_wide = pd.DataFrame(
np.random.random_integers(1, size=(1, len(string.ascii_letters))),
columns=list(string.ascii_letters))
with pd.option_context('display.max_columns', 10):
print(pd.options.display.max_columns)
print(df_wide)
print(pd.options.display.max_columns)
print(df_wide)
10
a b c d e ... V W X Y Z
0 1 1 1 1 1 ... 1 1 1 1 1
[1 rows x 52 columns]
20
a b c d e f g h i j ... Q R S T U V W X Y Z
0 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1 1
[1 rows x 52 columns]
In [ ]: