Dealing with columns in Python for Data Science:
To deal with columns, we need to perform basic operations on columns such as selecting, adding, detecting, and renaming.
Selection of column:
Selection of a column in Pandas DataFrame is done by calling their column names.
For adding a column in Pandas dataframe, we have to declare a new list as column, and we need to add it to the existing dataframe.
To delete column in Pandas dataframe we use the drop() method. Columns can be deleted by dropping columns with column names.
Data frame before dropping columns:
Data frame after dropping columns:
Dealing with rows:
We can perform basic operations on rows such as selecting, adding, deleting, and renaming.
Pandas provides a method for retrieving rows from data frame .DataFrame.loc is used for retrieving rows from Pandas DataFrame. We can also select rows by passing integer location to iloc function.
Addition of rows:
For addition of rows in Pandas DataFrame, concatenation of old dataframe with new one is possible.
Data frame before adding row:
Data frame after adding row:
For the deletion of a row in Pandas DataFrame, we use the drop() method. Rows can be deleted by dropping rows by index label.
As we see in the images below, the new output does not have passed values. These values were dropped and changes were made in original data frame since inplace was True.
Dataframe before dropping values:
Dataframe after dropping values: