Drop pandas DataFrame Column by Index in Python (Example) | Remove & Delete One Or Multiple Columns

preview_player
Показать описание
Python code of this video:

import pandas as pd # Load pandas library

data = pd.DataFrame({'x1':range(20, 26), # Create pandas DataFrame
'x2':['a', 'd', 'c', 'd', 'a', 'b'],
'x3':range(27, 21, - 1),
'x4':['a', 'b', 'c', 'd', 'e', 'f'],
'x5':['x', 'z', 'y', 'x', 'z', 'x']})
print(data) # Print pandas DataFrame

print(data_new1) # Print updated DataFrame

drop_list = [1, 2, 4] # Create list of indices
print(drop_list) # Print list of indices
# [1, 2, 4]

print(data_new2) # Print updated DataFrame

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

Hi, thank you so much fr your content!
this is exactly what I was looking for.

enderbreak