pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.7k stars 17.91k forks source link

Very frustrating not to be able to apply per-column date formats exporting to Excel #30275

Open stevecj opened 4 years ago

stevecj commented 4 years ago

When exporting to Excel, it is possible to add multiple number formats and then use set_column to apply any desired numeric format to any column. Attempting to do the same for date or date-time columns has no effect however.

It is possible to set a format for all date columns or all date-time columns using the date_format and datetime_format arguments to ExcelWriter(), but that applies a single format to all dates and a single format to all date-time values.

In my particular case, I have a column that is intended to represent a whole month, and I want to format it as such in the exported data, and I have other date columns that represent specific dates. There is apparently no way to accomplish that. Why?

Why not simply allow applying date formats to columns just as one can apply numeric formats to columns?

stevecj commented 4 years ago

Suggested pattern:

Pass False as the value to date_format and/or datetime_format to indicate that the formats for columns of those types should not be set automatically.

WillAyd commented 4 years ago

I think this would be a logical enhancement - interested in submitting a pull request @stevecj ?

stevecj commented 4 years ago

I haven't worked on Pandas source before, but I'll certainly give it a shot.

stevecj commented 4 years ago

Short on time. Still plan to try making this enhancement at some point if nobody beats me to it.

shraddhazpy commented 3 years ago

If @stevecj isn't working on it, I would want to take it.

MarcoGorelli commented 3 years ago

go ahead, thanks @shraddhazpy

shraddhazpy commented 3 years ago

take

shraddhazpy commented 3 years ago

Suggested pattern:

Pass False as the value to date_format and/or datetime_format to indicate that the formats for columns of those types should not be set automatically.

@MarcoGorelli just wanted to ensure that this is the pattern to be followed.

MarcoGorelli commented 3 years ago

Looks like it - I think the suggestion is to make something analogous to float_format, but for dates