# Data Science Python Cheat Sheet

Posted : admin On 1/2/2022- Data Science Python Cheat Sheets
- Python For Data Science Cheat Sheet Numpy Basics
- Python Basics Cheat Sheet
- Python For Data Science Cheat Sheet Scikit Learn

You have just started with python and looking for a python data science cheat sheet I have added some gathered from different resources. This will help you a lot because this cheatsheet for python is also helpful for those who are interested in data science.

- Importing Data: Python Cheat Sheet. January 11th, 2018 A cheat sheet that covers several ways of getting data into Python: from flat files such as.txts and.csv to files native to other software, such as Excel, SAS, or Matlab, and relational databases such as SQLite & PostgreSQL.
- Pandas Cheat Sheet For Data Science In Python. 1 Comment / Data / By Rahman. For working with data in python, Pandas is an essential tool you must use. This is a fast, powerful, flexible and easy to use open source data analysis and manipulation tool, built on top of the Python programming language.

This cheat sheet is free additional material that complements DataCamp's Intro to Python for Data Science course, where you learn by doing. (Above is the printable version of this cheat sheet).

This will help you as a handy guide and you can refer to it whenever you have doubts. So letâ€™s start with python basic elements.

**Python Basics**

Thanks, I hope this will help you, and if you want to recommend some please free to reach us. Also, share with your friends to help them.

But if you are absolute beginner and looking for free data science courses using python refer to our article here.

*My little collection of Python recipes for data science featuring Pandas, Matplotlib, and friends.*

## Pandas: reading a CSV from a string

In **Pandas** we can load data from a CSV file with `read_csv`

:

Now, it's not uncommon to have some tabular data as a string:

To load this **string as a file** we can use Python built-in `StringIO`

:

Credits to my friend Ernesto for this tip.

## Data Science Python Cheat Sheets

## How to plot a CSV with Pandas

Consider this file-like CSV:

To **plot this CSV with Pandas** we call the `plot`

method on the DataFrame:

To **show the plot** instead we call `show`

on `plt`

:

## Python For Data Science Cheat Sheet Numpy Basics

You can also **save the plot** with `savefig`

:

Now, you'll notice that the resulting picture has indeed **two labels taken from the CSV column. But the x axis is associated with the indexes of each DataFrame row**:

A DataFrame in fact has indexes:

**To use the year column instead of an index for the x axis** we can instruct `plot`

respectively with the x and y arguments (in this example you can omit y):

Now the plot is coherent with the dataset:

## How to groupby in Pandas

Suppose you've got a CSV with two columns, year and amount:

## Python Basics Cheat Sheet

To compute the **amount by year** you can group by year and then call `sum`

:

## Python For Data Science Cheat Sheet Scikit Learn

This gives you a new DataFrame as expected: