Python Pandas Tutorial | Drop Rows and Columns of a Pandas Dataset - P1

Python Pandas Tutorial | Drop Rows and Columns of a Pandas Dataset - P1

technologyCult

55 лет назад

2,148 Просмотров

Python Pandas Tutorial | Drop Rows and Columns of a Pandas Dataset - P1
Topics to be covered:
1. Dropping a Single Column of a dataset.
2. Dropping multiple Column of a dataset.
3. Dropping the Column of a dataset based on the Column Index.
4. Dropping the Multiple Column of a dataset based on the Column Index.

import pandas as pd
import numpy as np

dataset = pd.read_csv('train.csv')

1 Dropping a Single Column of a dataset based on the column name
df1 = dataset.drop('Name',axis=1)
print(df1.head())

2.Dropping multiple Column of a dataset based on the column name

df1 = df1.drop(['Pclass','Cabin'],axis=1)
print(df1.head())

3. Dropping the Column of a dataset based on the Column Index
df1 = df1.drop(df1.columns[1],axis=1)
print(df1.head())

4. Dropping the Multiple Column of a dataset based on the Column Index
df2 = df1.drop(df1.columns[[1,3]],axis=1)
print(df2.head())

5. Deleting rows of a dataset and copying the resultant dataset to a new dataframe
df3 = df2.drop(df2.index[[1,3]])
print(df3.head())

# 6. Drop the Duplicate Values based on some conditions
df3 = df3[df3['Embarked'] != 'S'].head()
print(df3.head())


Dup = df3.drop_duplicates().head()

Dup = Dup.drop_duplicates(subset=['Embarked'])

print(Dup)

Dup1 = df3.drop_duplicates(subset=['Embarked'], keep='last')

print(Dup1)

Тэги:

#Python #Machine_Learning #pandas #drop #delete #duplicates #python_drop_rows #how_to_delete_a_colum_from_table_in_python_in_machine_learning #machine_learning_tutorial #pandas_python_data_analysis #how_to_delete_rows_in_dataframe #pandas_dataframe #pandas_dropna #data_analysis #dataframe #what_is_pandas #Drop_Rows_and_Columns_of_a_Pandas_Dataset #How_to_drop_rows_of_pandas_dataset #How_to_drop_column_of_pandas_dataset #Pandas_drop_columns #Pandas_drop_drows
Ссылки и html тэги не поддерживаются


Комментарии: