df_store_index_list = df_store.index.tolist()
df_store_column_list = df_store[column].tolist()
list_to_be_returned = []
for i in range(len(df_store_index_list)):
list_to_be_returned.append([df_store_index_list[i], df_store_column_list[i]])
# return list_to_be_returned
return [[df_store_index_list[i], df_store_column_list[i]] for i in range(len(df_store_index_list)) ] not working!!!!
I have a function that returns a two-dimensional list.
Problem: the list comprehension on the last line is giving me an error saying "df_store_index_list is not defined".
Solution: I created my own list (list_to_be_returned) and did a custom for loop and it's working fine. It has a value (list_to_be_returned). But I was just wondering, why is the list comprehension not working?
here is the complete code
@classmethod
def store_specific_info_string(cls, store_name, column, ascending=False):
"""
Brief
- filter for specific store
Description
- obtain sum of column based on specific `Store_Name`
Parameter
- store_name : inside the `Store_Name` column
- ascending : True or False
- column : sum of what column? (Total_Sales, Total_Profit)
Return Value(s)
- tuple of name(Item_Description) and sum of column passed based on name.
"""
# filter the store by store name
df_store = cls.dataframe[ cls.dataframe[ "Store_Name" ] == store_name]
df_store = df_store.groupby("Item_Description").sum()[[column]]
# sort them by the column(integer)
df_store.sort_values(column,ascending=ascending ,inplace=True)
df_store_index_list = df_store.index.tolist()
df_store_column_list = df_store[column].tolist()
list_to_be_returned = []
for i in range(len(df_store_index_list)):
list_to_be_returned.append([df_store_index_list[i], df_store_column_list[i]])
return list_to_be_returned
# return [[df_store_index_list[i], df_store_column_list[i]] for i in range(len(df_store_index_list)) ] not working!!!!
here is a pdb initiated inside pdb