user11645903
user11645903

Reputation:

How i can create dataframe of specific interval columns by index number

I have dataframe of 130 columns, i wants to make df of each 10th column start from 0th then 3rd column and then wants to add 10

for ex:

df.columns = [0,3,13,23,33,43,53,63,73,83,93,103,113,123] 

Upvotes: 1

Views: 449

Answers (1)

Rakesh
Rakesh

Reputation: 82755

This is one approach using slicing

Ex:

columns = list(range(0, 131))     #sample column --> df.columns.tolist() 
result = [columns[0]] + columns[3::10]
print(result)

Output:

[0, 3, 13, 23, 33, 43, 53, 63, 73, 83, 93, 103, 113, 123]

To create new DF

new_df = df[result].copy()

Upvotes: 1

Related Questions