I have a pandas dataframe with only one row and hundreds of columns and I want to create a list of strings where the elements are the column names of the dataframe for which the value meet a condition. I also want to concatenate a specific text to each element. Here's the dataframe:
df = pd.DataFrame(data={
'name': ["Jimmy"],
'SN522': [0],
'SN521': [1],
'SN520': [0],
'SN519': [1],
'SN518': [0]})
I want all the column names where the row = 0, and adding the text "AN" at the beginning, and all separed by "-" The expected output would be this character:
cols0 = "ANSN522 - ANSN520 - ANS518"
In R it would be something like this (not sure):
column_0 <- paste(paste0("AN",c(colnames(df)[which(df[1,]==0)])),sep="-")
I tried first step using a for loop:
column_0 = [i for i in df.columns if df.i == 0] but I have an error: AttributeError: 'DataFrame' object has no attribute 'i'
I haven't figured out how to solve it yet, do you have an idea?