to_csv writes wrong with NaN value
See original GitHub issueto_csv with Nan value at top row, unexpected “” in the csv file
import pandas as pd
df = pd.DataFrame([None,1,2])
df.to_csv("df.csv",header=None,index=None,encoding ='utf-8')
# df.csv
#""
#1.0
#2.0
# I want to make df.csv
#
#1.0
#2.0
Versions:
pandas.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.2.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.20.3
pytest: None
pip: 9.0.1
setuptools: 36.4.0
Cython: None
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: 6.1.0
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.9999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None
Issue Analytics
- State:
- Created 6 years ago
- Comments:23 (21 by maintainers)
Top Results From Across the Web
Pandas Changing the format of NaN values when saving to CSV
But when I write the df to csv - the output contains the string 'nan' as oppose to being NULL. I have looked...
Read more >Why “df.to_csv” could be a Mistake ? | by Elfao | Analytics Vidhya
1. Save data as CSV file don't save format. You have already imported CSV files and noticed that columns formats have disappeared. ·...
Read more >pandas.read_table — pandas 1.5.2 documentation
Whether or not to include the default NaN values when parsing the data. ... DataFrame.to_csv. Write DataFrame to a comma-separated values (csv) file....
Read more >Missing values - Introduction to Python Workshop
NaN values are undefined values that cannot be represented mathematically. Pandas, for example, will read an empty cell in a CSV or Excel...
Read more >Reading and Writing CSV Files in Python with Pandas
The article shows how to read and write CSV files using Python's ... Sometimes, DataFrame s have missing values that we've left as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jackasser @jreback @gfyoung Actually, the double quoted blank field is the default spec. when writing single column CSV. IOW, this issue is the correct behavior, but the “Case 1” in https://github.com/pandas-dev/pandas/issues/18676#issuecomment-350205767 was wrong behavior. This is now fixed in CPython and the patch is backported to CPython 3.6. https://github.com/python/cpython/pull/4769
Please note that this bug does not exist in CPython 2.7.
@jreback Okay! (That fix is not released yet, will be included in the next release of CPython 3.6.)