I want to create a new dataframe that will be exported to csv using selected columns from the existing dataframe.
I've tried using a for loop to add every column within range(14, var_x, 2). So all the even numbered columns after columns[14].
original code:
var_col_length=len(df.columns)
for x in range(14, var_col_length, 2):
new_dataframe=df[df.columns[x]]
using append:
var_col_length=len(df.columns)
for x in range(14, var_col_length, 2):
new_dataframe=new_dataframe.append(df[df.columns[x]])
TypeError: '<' not supported between instances of 'str' and 'int'
I either get only the last column, since as expected of the above code it keeps rewriting the dataframe "new_dataframe", when I tried using .append I get an error:
TypeError: '<' not supported between instances of 'str' and 'int'.