Hacker Public Radio

HPR3253: Pandas Intro


Listen Later

Welcome to another episode of HPR I'm your host Enigma and today we are going to be talking
about one of my favorite python modules Pandas
This will be the first episode in a series I'm naming: For The Love of Python.
First we need to get the module
pip or pip3 install pandas
This will install numpy as well
Pandas uses an object called a dataframe which is a two-dimensional data structure,
i.e., data is aligned in a tabular fashion in rows and columns. Think of a spreadsheet type object in memory
Today we are going to talk about:
1) Importing data from various sources
Csv, excel, sql. More advance topics like Json covered in another episode.
df = pd.read_csv('file name')
2) Accessing data by column names or positionally
print(df.head(5)) # print all columns only first 5 rows
print(df.tail(5)) # print all columns only last 5 rows
print(df.shape) # print number of rows and columns in dataframe
print(df.columns) print column names
print(df[0:1].head(5)) print first two columns first 5 values by column position
print(df['field1].head(5)) print same column first five values by column name
3) Setting column types.
df['FieldName'] = df['FieldName'].astype(int) # sets column as interger
df['FieldName'] = df['FieldName'].astype(str) # sets column to string
df['DateColumn'] = pd.to_datetime(df['DateColumn']) # sets column to Datetime
4) Some basic filtering/manipulation of data.
Splits string at the @ for one split next two lines create 2 columns that use the pieces.
new = df2["Email"].str.split("@", n = 1, expand = True)
df2["user"]= new[0]
df2["domain"]= new[1]
df['col'] = df['Office'].str[:3] # creates a new column grabing the first 3 positions of Office column
df = df[df['FieldName'] != 0] # Only keep rows that have a FieldName value not equal to zero
See example code that you can run at:
Pandas Working example
...more
View all episodesView all episodes
Download on the App Store

Hacker Public RadioBy Hacker Public Radio

  • 4.2
  • 4.2
  • 4.2
  • 4.2
  • 4.2

4.2

34 ratings


More shows like Hacker Public Radio

View all
The Changelog: Software Development, Open Source by Changelog Media

The Changelog: Software Development, Open Source

290 Listeners

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec by Jerry Bell and Andrew Kalat

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec

372 Listeners

LINUX Unplugged by Jupiter Broadcasting

LINUX Unplugged

268 Listeners

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast) by Johannes B. Ullrich

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast)

651 Listeners

Curious Cases by BBC Radio 4

Curious Cases

821 Listeners

The Strong Towns Podcast by Strong Towns

The Strong Towns Podcast

423 Listeners

Late Night Linux by The Late Night Linux Family

Late Night Linux

164 Listeners

Darknet Diaries by Jack Rhysider

Darknet Diaries

8,066 Listeners

Cybersecurity Today by Jim Love

Cybersecurity Today

179 Listeners

CISO Series Podcast by David Spark, Mike Johnson, and Andy Ellis

CISO Series Podcast

189 Listeners

TechCrunch Daily Crunch by TechCrunch

TechCrunch Daily Crunch

42 Listeners

Strict Scrutiny by Crooked Media

Strict Scrutiny

5,799 Listeners

2.5 Admins by The Late Night Linux Family

2.5 Admins

98 Listeners

Cyber Security Headlines by CISO Series

Cyber Security Headlines

139 Listeners

What the Hack? by DeleteMe

What the Hack?

229 Listeners