Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QST: How to export json as zip without directories #41517

Closed
danymat opened this issue May 17, 2021 · 3 comments
Closed

QST: How to export json as zip without directories #41517

danymat opened this issue May 17, 2021 · 3 comments
Labels
Enhancement IO Data IO issues that don't fit into a more specific label Needs Discussion Requires discussion from core team before further action

Comments

@danymat
Copy link

danymat commented May 17, 2021

Hello Everyone, I searched a possible answer for my question without success.

Suppose I start my python script in the root directory of this structure tree:

.
├── Dockerfile
├── files
├── scripts

In this script I read a csv from files, with a read_csv('files/filename.csv')

When I try to export a modified dataframe with to_json('files/export.zip', compression='zip'), I get a zipped file with the correct name, but when unzipping, I get a folder named files, and the json inside.

How can I export the json file in zip without having the root files directory listed ?

Note: This is a related problem below, but I was hoping a builtin solution with to_json()
https://unix.stackexchange.com/questions/182032/zip-the-contents-of-a-folder-without-including-the-folder-itself

@danymat danymat added Needs Triage Issue that has not been reviewed by a pandas team member Usage Question labels May 17, 2021
@twoertwein
Copy link
Member

to_csv does the same. Changing the behavior should be fairly easy, simply adding

if archive_name is not None:
    archive_name = os.path.basename(archive_name)

before

self.archive_name = archive_name

Do you want to create a PR? This probably needs some discussion as some people might expect the nested behavior.

@lithomas1 lithomas1 added Needs Discussion Requires discussion from core team before further action 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 May 21, 2021
@robbiesumner
Copy link

I tried it myself and it didn't happen for me, the zip archive gives me only the export json. Is this still an issue?

@mroeschke
Copy link
Member

Thanks for the issue, but it appears this hasn't gotten traction in a while so closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO Data IO issues that don't fit into a more specific label Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

No branches or pull requests

5 participants