List of strings to create a new list of strings without quotes?

Question:

Data

crop_list = ['Cotton','Ragi', 'Groundnut', 'Sugarcane', 'Redgram', 'Sunflower', 'Paddy', 'Maize','Jowar']

Now each element is DataFrame

for a in crop_list:
    vars()[a] = Data[Data['Crop']== a]

For next line of codes i might need to create a list manually, i.e. dfs

from functools import reduce
dfs =[Cotton,Ragi,Groundnut,Sugarcane,Redgram,Sunflower,Paddy,Maize,Jowar]
df_merged = reduce(lambda a,b: pd.merge(a,b, on='Year'), dfs)

so im asking is there any way to get dunamic list:
Expected output:

Another List with same strings without quotes:

new_crop_list = [Cotton,Ragi, Groundnut, Sugarcane, Redgram, Sunflower, Paddy,Maize,Jowar]
Asked By: Manojkumar Patil

||

Answers:

I think this is basically what you meant

crop_list = ["'Cotton'","'Ragi'", "'Groundnut'", "'Sugarcane'", "'Redgram'", "'Sunflower'", "'Paddy'", "'Maize'","'Jowar'"]

Since without quotes, a string is not a string, if this is the case. You can remove the single quotes from the list using the following code

new_list = [ x.replace("'","") for x in crop_list]

The above code will remove single quotes from around the values in the list.
The output will look like

['Cotton', 'Ragi', 'Groundnut', 'Sugarcane', 'Redgram', 'Sunflower', 'Paddy', 'Maize', 'Jowar']

You will still see single quotes in output, since its a list of strings, and the quotes denotes that .

Hope this answers your question

Answered By: Hassan Jalil
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.