Upon doing some research online there does not seem to by any simple way to just order a dictionary
My Dict contains a list with each name being the key
dummy_data = {"Date":["01/24/2029","10/28/2027", "01/24/2024","03/24/2024"],"Company Name":["Mcdonalds", "Burger King", "KFC","Popeyes"],"File_name_location":["C/Documents/Files/invoice1.pdf", "C/Documents/Files/invoice1.pdf","C/Documents/Files/invoice1.pdf"], }As you see with the above I have a field called Date which list the dates in random order. I would like to get the least to greatest dates but then also ensuring the "Company Name" as well gets moved around
Based on some information I would have to change the Date to a datetime which I did by
for index, result in enumerate(dummy_data["Date"]): dummy_data["Date"][index] = datetime.strptime(dummy_data["Date"][index], "%m/%d/%Y").date()I know there is a much faster way on changing the Date to a date very quickly with lambda but I am not familar with lambda enough just yet.
In any case another issue is that I would also like if possible to keep my date with the slash if that was even possible but it seems that it may not even possible because the .date() returns it in this format **(01-24-2029) ** but also I would now have to wrap the datetime in a str otherwise the Date list will have objects of datetime in them rather than the string data.
My ultimate goal is
- Sort by Date and making sure "Company Name" also keeps the correct index of the above
- If possible keep the dates with the slashes if not possible then no worries.
I know there is an OrderedDict class but I am not familiar with this as I believe this uses some sort of function like a lambda as a parameter.
- If it even matters whyThe reason I would like to sort by dates is because these dates are being pulled in by some invoices which I am using a PDFREADER to read the dates and then I would to ultimately merge the pdfs together but it will be merged by the date of the file meaning the file with the "least" date will be put on top or bottom depending on what I want. In any case if anyone feels like they have some sort of workaround please get back to me.
also for whatever reason I did try
sorted_val = str(sorted(dummy_data["Date"]))I double checked the above and it actually did not sort anything