Python Forum
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Menu Problem.
#11
(Jul-08-2018, 11:07 PM)carpe Wrote:
Quote:Could you please give me a rough outline of option 1? To show me what I need to progress to. It would be much appreciated as I have small experience in python.

Assuming the original text file looks something similar to...

Member ID Surname Year Joined Membership Status Nights Booked Points Balance
Gri33415 Griffiths 2015 Gold 35 40000
Smi22316 Smith 2016 Silver 3 7500
Mia56213 Miah 2013 Platinum 140 165000
...

tThen something like...

import pandas as pd

def read_text():

    data_frame = pd.read_csv("/path/to/relevant/file/textfile.txt", sep=" ", skiprows=[0], header=None)
    data_frame.columns = ["Member ID", "Surname", "Year Joined", "Membership Status", "Nights Booked", "Points Balance"]

    return data_frame
... should get the data loaded in and ready to use.


Hello again!

Panda is not installed on the school computers and I cannot get it installed, meaning that the code is invalid!

I have a text.txt file saved within my drive and also on the document, I need to make a function so that it displays in the correct parameters of ID, Name, etc. This is my text file:

(Text.txt)

[Gri33415,Griffiths,2015,Gold,35,40000] [Smi77316,Smith,2016,Silver,3,7500] [Mia56213,Miah,2013,Platinum,140,165000]
[All78915,Allen,2015,Platinum,120,145000] [Hug91714,Huggett,2014,Platinum,150,50000] [Sel77617,Selby,2017,Gold,40,45000]
[San55614,Santus,2014,Silver,17,30000] [Lee44213,Leewah,2013,Silver,15,37500]


Can you help me to find some code that will make a def function to run this when someone selects an option from my menu, please. I am really stuck: Here is my menu, if some code is provided, could you also tell me where I need to put the code and anything else I need to do to make it run when the user selects the option to show members, Thanks!





print("???????????????")
print("?? A: Add new member ??")
print("? B: Book a night. ??")
print("?? C: Redeem points ??")
print("? D: Show members. ??")
print("?? E: Quit ??")
print("????????????????")


answer =str.lower(input(("Please select an option")))
if answer == "a":
print("Okay, lets start")

elif answer == "b":
print("Okay, lets start")

elif answer == "c":
print("Okay, lets start")

elif answer == "d":
print("Okay, lets start")

elif answer == "e":
print("Exited")

else:
print("Invalid")
Reply
#12
I almost spoke up when Pandas was mentioned originally...

It's not needed. Just use JSON, it's built-in and used very widely (rather than being used mostly in data science, like Pandas).
Reply
#13
(Jul-10-2018, 07:20 PM)micseydel Wrote: I almost spoke up when Pandas was mentioned originally...

It's not needed. Just use JSON, it's built-in and used very widely (rather than being used mostly in data science, like Pandas).


Could you please explain how to use JSON in my context with the panda script he gave me? Never used it before!
Reply
#14
Don't use Pandas.

Once you've built a list/dict in memory that you want to store to disk, then you should look at using JSON. There are plenty of resources that have examples, I suggest you give it a try and then post back with something specific.

I don't say this to torture you, I say it because you'll learn a lot more and because your projects sounds far too large to go through each little thing together. Your programming-related research skills will develop and you'll find each new task gets easier.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020