0

I have a dataframe which look like this:

xl_file
Out[2]: 
                  Day                     Description
Date                                                 
2011-01-26  Wednesday                    Republic Day
2011-03-02  Wednesday                   Mahashivratri
2011-04-12    Tuesday                       Ram Navmi
2011-04-14   Thursday  Dr. Babasaheb Ambedkar Jayanti
2011-04-22     Friday                     Good Friday
              ...                             ...
2020-05-25     Monday          Id-Ul-Fitr (Ramzan ID)
2020-10-02     Friday          Mahatma Gandhi Jayanti
2020-11-16     Monday            Diwali-Balipratipada
2020-11-30     Monday               Gurunanak Jayanti
2020-12-25     Friday                       Christmas

[144 rows x 2 columns]

This was imported from an excel file. I was wondering if there is a way where once it is imported into a dataframe, i can permanently save it somehow. Such that i do not have to keep the excel file and reimported it to dataframe.

6
  • 2
    Does this answer your question? stackoverflow.com/questions/17098654/… Commented May 25, 2020 at 19:46
  • Permanently save it where? It already was saved in a file format Commented May 25, 2020 at 19:49
  • Does this answer your question? How to store a dataframe using Pandas Commented May 25, 2020 at 19:53
  • Did you made any changes after importing in the dataframe? Else you can just import every time you want to use. Commented May 25, 2020 at 19:57
  • @roganjosh I just want it so that once the data from the file is imported and i convert the script to .exe there should not be any other files just the .exe . Is that possible? Commented May 25, 2020 at 20:13

2 Answers 2

1

[Update] As mentioned in the comments, If you want to use the data to make executable and do not want a dependency on any other file then you can store it as a dictionary lookup table and load it from that.

data= {<your dictionary created from excel file>}

xl_file = pd.DataFrame.from_dict(data)

Otherwise, you can write the dataframe in the CSV format in the disk

xl_file.to_csv("csv_filename.csv")

If you want to store it as an object, pickle could be the way, however, it can take more memory space.

Sign up to request clarification or add additional context in comments.

6 Comments

How, exactly, does this differ from the file that they want to now delete? You may have made it more universal, but the exact same circumstance exists... they have a file
If no changes made in the excel content then it is no different. I believe there might be several operations made on the dataframe which the user wants to save and not do again. Otherwise, I do not see the purpose of the question
I'm not clear on the purpose of the question, either. But if they can parse an Excel file in, then they can also just save it back as an Excel file. And overwrite existing content if things change. It's no different to a CSV
Ahhh.. Okay got the purpose. Then a look_up table like a dictionary could be the way if you have a small dataframe.
Updated the answer, see if you find it useful
|
1

Python stores variables (including your imported dataframe) in memory, and memory is volatile (i.e. it only retains data while it's powered). In fact, you lose any data stored in memory as soon as your Python program stops running. So the only way to save data permanently is to save it to disk - which you have already done with your excel file - or save it to a remote location (cloud storage, external DB, etc.)

You can however import the excel file and export it again (to disk) in a way that is easier and faster to parse - this might include either saving it to a different format, for example as a csv (see instructions here), or cleaning-up the dataframe and getting rid of any data you don't need to read.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.