I have the following dataframe:
df_Station = pd.DataFrame({'Name': ['Station 1024', 'Station 1024',
'Station 1024', 'Station 1024',
'Station 5588', 'Station 5588',
'Station 1211', 'Station 1211',
'Station 1211', 'Station 1200'],
'Type': ['Weather_type1', 'Weather_type2',
'Weather_type2', 'Weather_type3',
'Weather_type1', 'Weather_type1',
'Space_type4', 'Space_type5',
'Space_type4', 'Space_type5']})
print(df_Station)
Name Type
Station 1024 Weather_type1
Station 1024 Weather_type2
Station 1024 Weather_type2
Station 1024 Weather_type3
Station 5588 Weather_type1
Station 5588 Weather_type1
Station 1211 Space_type4
Station 1211 Space_type5
Station 1211 Space_type4
Station 1200 Space_type5
I apply one filter, according to a constant that is defined:
cteName = 'Station 1024'
df_Station_Specific_Name = df_Station[df_Station['Name'] == cteName]
I apply another filter, according to a constant that is defined:
cteType = 'Weather_type2'
df_Station_Specific_Name_Type = df_Station_Specific_Name[df_Station_Specific_Name['Type'] ==
cteType]
Then, I do several operations on the filtered dataframe. For example, inserting a new column:
df_Station_Specific_Name_Type['New_Columns'] = 1
print(df_Station_Specific_Name_Type)
Name Type New_Columns
Station 1024 Weather_type2 1
Station 1024 Weather_type2 1
Finally, I save this final dataframe. The file of type csc will contain the name of the two constants for easy identification.
df_Station_Specific_Name_Type.to_csv('Result_%s_%s' %(cteName, cteType))
The code works perfectly. My question is as follows:
I would like to generate several outgoing dataframes, as changing the two constants, that is, making a combination between them.
For example, for cteName = Station 1024 I would like to run for all unique types (Weather_type1, Weather_type2 ...)
Would there be an automatic way to do this? without having to keep changing the constants cteName and cteType.
Note: the operation performed, adding a column, is just an example. After filtering the dataframe, several operations are performed. I am using Jupyter Anaconda line execution.
Thanks for the help.