You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
copy this text, or data from excel/libreoffice with the same shape
col1 col2
1 red
blue
2 green
In [3]: pandas.read_clipboard()
Out[3]:
col1col201red1blueNone22green
Problem description
Using read_clipboard() on excel data when there are null values on the first few rows of the first columns causes pandas to use the default separator instead of the "\t" used for excel.
The result is the values shift into the wrong column
Expected Output
In [4]: pandas.read_clipboard()
Out[4]:
col1col201.0red1NaNblue22.0green
Output of pd.show_versions()
INSTALLED VERSIONS
commit : 2cb9652
python : 3.9.3.final.0
python-bits : 64
OS : Linux
OS-release : 5.11.11-zen1-1-zen
Version : #1 ZEN SMP PREEMPT Tue, 30 Mar 2021 14:10:21 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.utf8
LOCALE : en_US.UTF-8
reproduces, and should ideally be fixed there if it is a bug (i'll leave that for others to determine). Specifying sep='\t' provides your output for both read_clipboard and read_csv.
In [17]: pd.read_clipboard(sep='\t')
Out[17]:
col1col201.0red1NaNblue22.0green
yes this only happens if you let pandas infer the format, without specifying a separator, it is this part that does it:
# Excel copies into clipboard with \t separation# inspect no more then the 10 first lines, if they# all contain an equal number (>0) of tabs, infer# that this came from excel and set 'sep' accordinglylines=text[:10000].split("\n")[:-1][:10]
# Need to remove leading white space, since read_csv# accepts:# a b# 0 1 2# 1 3 4counts= {x.lstrip().count("\t") forxinlines}
iflen(lines) >1andlen(counts) ==1andcounts.pop() !=0:
sep="\t"
jreback
added
IO Data
IO issues that don't fit into a more specific label
and removed
Needs Triage
Issue that has not been reviewed by a pandas team member
labels
Apr 26, 2021
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
copy this text, or data from excel/libreoffice with the same shape
Problem description
Using read_clipboard() on excel data when there are null values on the first few rows of the first columns causes pandas to use the default separator instead of the "\t" used for excel.
The result is the values shift into the wrong column
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 2cb9652
python : 3.9.3.final.0
python-bits : 64
OS : Linux
OS-release : 5.11.11-zen1-1-zen
Version : #1 ZEN SMP PREEMPT Tue, 30 Mar 2021 14:10:21 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.utf8
LOCALE : en_US.UTF-8
pandas : 1.2.4
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 20.3.3
setuptools : 49.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: