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.
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