Git Product home page Git Product logo

python-data-wrangling-legacy's Introduction

D-Lab Python Data Wrangling Workshop

Datahub Binder

This repository contains the materials for D-Lab's Python Data Wrangling workshop. Prior experience with Python Fundamentals is assumed.

Workshop Goals

In this workshop, we provide an introduction to data wrangling with Python. We will do so largely with the pandas package, which provides a rich set of tools to manipulate and interact with data frames, the most common data structure used when analyzing tabular data. We'll learn how to manipulate, index, merge, group, and plot data frames using pandas functions.

Basic familiarity with Python is assumed. If you are not familiar with the material in Python Fundamentals, we recommend attending that workshop first.

Installation Instructions

Anaconda is a useful package management software that allows you to run Python and Jupyter notebooks very easily. Installing Anaconda is the easiest way to make sure you have all the necessary software to run the materials for this workshop. Complete the following steps:

  1. Download and install Anaconda (Python 3.8 distribution). Click "Download" and then click 64-bit "Graphical Installer" for your current operating system.

  2. Download the Python-Data-Wrangling workshop materials:

  • Click the green "Code" button in the top right of the repository information.
  • Click "Download Zip".
  • Extract this file to a folder on your computer where you can easily access it (we recommend Desktop).
  1. Optional: if you're familiar with git, you can instead clone this repository by opening a terminal and entering git clone [email protected]:dlab-berkeley/Python-Data-Wrangling.git.

Run the code

Now that you have all the required software and materials, you need to run the code:

  1. Open the Anaconda Navigator application. You should see the green snake logo appear on your screen. Note that this can take a few minutes to load up the first time.

  2. Click the "Launch" button under "Jupyter Notebooks" and navigate through your file system to the Python-Data-Visualization folder you downloaded above.

  3. Open the lessons folder, and click 01_pandas.ipynb to begin.

  4. Press Shift + Enter (or Ctrl + Enter) to run a cell.

Note that all of the above steps can be run from the terminal, if you're familiar with how to interact with Anaconda in that fashion. However, using Anaconda Navigator is the easiest way to get started if this is your first time working with Anaconda.

Is Python not working on your laptop?

If you do not have Anaconda installed and the materials loaded on your workshop by the time it starts, we strongly recommend using the UC Berkeley Datahub to run the materials for these lessons. You can access the DataHub by clicking this button:

Datahub

The DataHub downloads this repository, along with any necessary packages, and allows you to run the materials in a Jupyter notebook that is stored on UC Berkeley's servers. No installation is necessary from your end - you only need an internet browser and a CalNet ID to log in. By using the DataHub, you can save your work and come back to it at any time. When you want to return to your saved work, just go straight to DataHub, sign in, and you click on the Python-Data-Wrangling folder.

If you don't have a Berkeley CalNet ID, you can still run these lessons in the cloud, by clicking this button:

Binder

By using this button, however, you cannot save your work.

Additional Resources

About the UC Berkeley D-Lab

D-Lab works with Berkeley faculty, research staff, and students to advance data-intensive social science and humanities research. Our goal at D-Lab is to provide practical training, staff support, resources, and space to enable you to use R for your own research applications. Our services cater to all skill levels and no programming, statistical, or computer science backgrounds are necessary. We offer these services in the form of workshops, one-to-one consulting, and working groups that cover a variety of research topics, digital tools, and programming languages.

Visit the D-Lab homepage to learn more about us. You can view our calendar for upcoming events, learn about how to utilize our consulting and data services, and check out upcoming workshops.

Other D-Lab Python Workshops

Here are other Python workshops offered by the D-Lab:

Introductory Workshops

Advanced Workshops

python-data-wrangling-legacy's People

Contributors

akesari12 avatar akokai avatar davclark avatar geoffbacon avatar henchc avatar juanshishido avatar ktakimoto avatar pssachdeva avatar samyag1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-data-wrangling-legacy's Issues

Explain DataFrame vs Series

We might want to add a little section at the start of the notebook to explain the difference between DataFrame and Series objects.

Incorrect header in the notebook

A minor error, but in introduction-to-pandas.ipynb file, the header:

Challenge 7: Another way to get the month

Should actually read:

Challenge 7: Another way to get the year

as the challenge requires to get the year component of the Dataframe column and not the month.

Curriculum Review: Practice interpreting data

Understand what it is that we’re looking at in the data is another useful skill - that i think most social science / stem grad students have, but for people who are new to data analysis, we can include more of that type of practice

`unemployment_rate` name

unemployment_rate is a bit of a weird name (as it’s not actual unemployment rates but a DF with null proportions for unemployment rates

Part 7 Let's Look at Our File Depends on OS

Part 7 says Exporting A DataFrame to csv
it looks at the file using the "!" but that is only viable in mac, not windows
!head -5 data/unemployment_missing.csv
to do: add windows version of terminal "!"

Suggested changes to pandas lesson

Possible things to consider for intermediate/advanced pandas class:

  • reading/writing to formats other than csv
  • reading data in by chunks
  • multi-indexing and its methods
  • sparse matrices and their methods
  • ways to speed up mathy things (lots of %timeit)
  • parallelized methods for pandas

We can both also look up other pandas materials and think of other things we might like to add.

Challenge 12 solution

The challenge 12 solution seems too complex. We can just do .dropna on our newly created ps column?

Minor typo in Readme

Click the "Launch" button under "Jupyter Notebooks" and navigate through your file system to the Python-Data-Visualization folder you downloaded above.

Should read Python-Data-Wrangling instead of Data Visualization

Explain `.round()`

Using .round() in Manipulating Columns needs to be explained. If we don’t use it, we will not get to a full integer and then calling int() will truncate. Compare ((unemployment['year_month'] - unemployment['year']) * 100).astype(int) and ((unemployment['year_month'] - unemployment['year']) * 100).round(0).astype(int) - the first starts at 0, second starts at 1

command line error

Part 7 has a line of code:
!head -5 ../data/unemployment_missing.csv

Head is a Unix/Linux specific function and folks who were using Windows locally cannot run this line.

pandas plotting

Add examples and descriptions for how to plot with pandas (e.g., pandas.DataFrame.plot).

double subsetting?

unemployment_rate_missing = unemployment[unemployment['unemployment_rate'].isnull()] -> no need for double subset

Suggestions for improvements

  1. unemployment_rate is a bit of a weird name (as it’s not actual unemployment rates but a DF with null proportions for unemployment rates
  2. unemployment_rate_missing = unemployment[unemployment['unemployment_rate'].isnull()] -> no need for double subset
  3. Using round() in Manipulating Columns needs to be explained. If we don’t use it, we will not get to a full integer and then calling int() will truncate. Compare ((unemployment['year_month'] - unemployment['year']) * 100).astype(int) and ((unemployment['year_month'] - unemployment['year']) * 100).round(0).astype(int) - first starts at 0, second starts at 1
  4. The challenge 12 solution seems too complex. We can just do .dropna on our newly created ps column?

Rename Repo

Name should be changed from "Introduction to Pandas" to "Python Data Wrangling and Manipulation With Pandas"

Spending more time on `groupby()`

Some of the participants asked if there could be more time spent on groupby(), as they need it for their research. I feel it's important to spend at least 20' on this section and challenge. Not sure if I have an immediate idea for how to do this -- another challenge after #10, giving more examples of groupby() functionalities or scenarios, introducing it earlier (e.g. before merging).

Missing values

Remove some values from the main CSV file

  • replace missing values with .fillna()
    • show method parameter
  • keep rows with no missing values with .dropna()

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.