question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how convert a dataframe with null values to csv?

See original GitHub issue

When i use to_csv in koalas for converting a Data-frame to CSV, the null values fill with \"\" , but i want null values be null. The code is:

df.to_csv(path='test', num_files=1) How can set koalas to don’t do this for null values?

when I canverto it to pandas and save the pandas dataframe evry thing is ok:

pdf =df.to_pandas()
pdf.to_csv('t.csv')

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MammadTavakolicommented, Dec 3, 2019

the problem is with space. when a cell value is space after save the as csv file, the space fill with \"\".

d = {'col1': ['a b ', '2'], 'col2': [' ', '4']}
kdf = ks.DataFrame(data=d, columns=['col1', 'col2'])
kdf.to_csv('t')

the problem solved with this code: kdf.to_csv('t', emptyValue='')

0reactions
HyukjinKwoncommented, Dec 3, 2019

Can you try to_csv(..., nullValue=" ")?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pandas Changing the format of NaN values when saving to CSV
I have tried a few things to set 'nan' to NULL but the csv output results in a 'blank' rather than NULL: dfDemographics...
Read more >
Pandas to_csv() - Convert DataFrame to CSV - DigitalOcean
Pandas DataFrame to_csv() function converts DataFrame into CSV data. We can pass a file object to write the CSV data into a file....
Read more >
pandas.DataFrame.to_csv — pandas 1.5.2 documentation
Write object to a comma-separated values (csv) file. Parameters ... Missing data representation. ... Column label for index column(s) if desired.
Read more >
Python | Pandas DataFrame.fillna() to replace Null values in ...
Sometimes csv file has null values, which are later displayed as NaN in Data Frame. Just like pandas dropna() method manage and remove...
Read more >
Convert Pandas DataFrame to CSV - Javatpoint
The Pandas to_csv() function is used to convert the DataFrame into CSV data. To write the CSV data into a file, we can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found