Go back to Home

Extracting multiple columns of a dataset and storing it as a dataframe [Python][Pandas]

Today I learned how to extract multiple columns from a dataset and store it in a dataframe for further analysis.

In this section, I want to display the following columns of the volcano dataset that caused a Tsunami ('Year', 'Month', 'day', 'Name','Location','Country').

import pandas as pd
vol = pd.read_csv("vol.txt",sep="\t",header=0)

Screen Shot 2019-03-06 at 8.12.25 PM

There are 2 parts:

1) Extraction of data

Screen Shot 2019-03-06 at 8.35.44 PM

tsunami_vol dataframe was created with required columns using Dataframe() function of pandas and set column = ["column names"]

2) Using subset to extact required rows of data (volcanos that caused tsunami)

Screen Shot 2019-03-06 at 8.22.19 PM

This displays the top 10 volcanos that caused a tsunami.