Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I create an output dataframe that uses user input in the name?

I was wondering if there was a way to name a dataframe that includes user input?

For example, I have the following code:

start_year = int(input("Enter a start year:"))
end_year = int(input("Enter an end year:"))
selected_jur = input("Enter a jurisdiction number to search for: ")
df_list=[]
df_dict ={}


###this is where I filter my data source to get it ready for the code below

print(f"Combined dataframe of {selected_jur} from {start_year} to {end_year}:")
print(combined_df)

I can get everything to work except for naming the dataframe by the ‘selected_jur’ and time periods. I have to use "combined_df" if I want to conduct further analyses.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Ideally, instead of "combined_df", I’d have the df be something like:

"combined_df_for_{selected_jur}from{start_year}to{end_year}" instead.

Is this possible?

Thank you in advance!

>Solution :

you could save that dataframe in a dictionary and use that label as the key, so instead of changing the variable name, you’re changing the key name like this:

df_dict[f"combined_df_for_{selected_jur}from{start_year}to{end_year}"] = combined_df

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading