Giter Site home page Giter Site logo

ntk38 / dsc-0-03-08-understanding-pandas-series-and-dataframes-lab-nyc-ds-career-012819 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from learn-co-students/dsc-0-03-08-understanding-pandas-series-and-dataframes-lab-nyc-ds-career-012819

0.0 1.0 0.0 2.21 MB

Jupyter Notebook 100.00%

dsc-0-03-08-understanding-pandas-series-and-dataframes-lab-nyc-ds-career-012819's Introduction

Understanding Pandas Series and DataFrames - Lab

Introduction

In this lab, let's get some hands on practice working with data cleanup using Pandas.

Objectives

You will be able to:

  • Manipulate columns in DataFrames (df.rename, df.drop)
  • Manipulate the index in DataFrames (df.reindex, df.drop, df.rename)
  • Manipulate column datatypes
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
df = pd.read_csv('turnstile_180901.txt')
print(len(df))
df.head()
197625
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
C/A UNIT SCP STATION LINENAME DIVISION DATE TIME DESC ENTRIES EXITS
0 A002 R051 02-00-00 59 ST NQR456W BMT 08/25/2018 00:00:00 REGULAR 6736067 2283184
1 A002 R051 02-00-00 59 ST NQR456W BMT 08/25/2018 04:00:00 REGULAR 6736087 2283188
2 A002 R051 02-00-00 59 ST NQR456W BMT 08/25/2018 08:00:00 REGULAR 6736105 2283229
3 A002 R051 02-00-00 59 ST NQR456W BMT 08/25/2018 12:00:00 REGULAR 6736180 2283314
4 A002 R051 02-00-00 59 ST NQR456W BMT 08/25/2018 16:00:00 REGULAR 6736349 2283384

Practice

Objectives

You will be able to:

  • Understand and explain what Pandas Series and DataFrames are and how they differ from dictionaries and lists
  • Create Series & DataFrames from dictionaries and lists
  • Manipulate columns in DataFrames (df.rename, df.drop)
  • Manipulate the index in DataFrames (df.reindex, df.drop, df.rename)
  • Manipulate column datatypes

Rename all the columns to lower case

#Your code here

Change the Index to be the Line Names

#Your code here

Painstakingly change the index back

# Your code here

Create another column 'Num_Lines' that is a count of how many lines pass through a station. Then sort your dataframe by this column in descending order.

# Your code here

Write a function to clean a column name.

def clean(col_name):
    cleaned = #Your code here; whatever you want to do to col_name. Hint: think back to str methods.
    return cleaned
#This is a list comprehension. It applies your clean function to every item in the list.
#We then reassign that to df.columns
#You shouldn't have to change anything here.
#Your function above should work appropriately here.
df.columns = [clean(col) for col in df.columns] 
#Checking the output, we can see the results.
df.columns

Compare subway traffic by day of the week. Display this as a graph.

#Your code here

Is there more subway traffic on a weekend or a weekday? Be specific in comparing magnitudes.

#Your code here

Drop a couple of columns

# Your code here

dsc-0-03-08-understanding-pandas-series-and-dataframes-lab-nyc-ds-career-012819's People

Contributors

peterbell avatar mathymitchell avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.