Description
-
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.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
columns = ["type", "symbol", "Date", "Time", "TSNumber", "Price", "Quantity", "SettlementDate", "Yield", "AccruedInterest", "ConditionCodes", "QuotationBasis", "ExchangeRate", "TradeAttributes"]
df = pd.read_csv("20200803.csv",dtype = str,names=columns)
Problem description
Reading in a csv file with the following line
T,FMG,20200803,000000,10071068,,,20200804,,,XT,,,,
results in pandas ignoring the 4th column, and matches the current column to the next value (10071068) in that case.
Previous reports suggested setting the dtype to string (see https://stackoverflow.com/questions/13250046/how-to-keep-leading-zeros-in-a-column-when-reading-csv-with-pandas), which should be fine if the column is read in as "0000000", but apparently it is not. Am I missing something?
Current output:
-- | -- | -- | -- | --
71068 | FMG | 20200803 | 10071068 | 20200803.0 ...
Expected Output
-- | -- | -- | -- | --
71068 | FMG | 20200803 | 000000 | 10071068 | 20200803.0 ...
Output of pd.show_versions()
INSTALLED VERSIONS
commit : 67a3d42
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.8.0-7642-generic
Version : #47161228899020.04~b8113e7-Ubuntu SMP Wed Feb 3 02:25:36 UTC 2
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.4
numpy : 1.19.4
pytz : 2020.4
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.3.3.post20210118
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : 0.5.0
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.22
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
numba : 0.52.0