# 2021-04-26 <br> SWD1a: Introduction to Python
Welcome to the hack pad for SWD1a course from Research Computing at the University of Leeds!
You can edit this document using [Markdown syntax](https://guides.github.com/features/mastering-markdown/).
## Contents
1. [Links to resource](#Links-to-resources)
2. [Agenda Day 1](#Agenda-Day-1)
3. [Agenda Day 2](#Agenda-Day-2)
4. [Agenda Day 3](#Agenda-Day-3)
5. [Agenda Day 4](#Agenda-Day-4)
6. [What's your name and where do you come from?](#What’s-your-name-and-where-do-you-come-from)
7. [Further reading](#Further-reading)
8. [Extra code snippets](#Misc-code-snippets)
## Links to resources
- **Contact Research Computing** - https://bit.ly/arc-help
- **Workshop Slides** - https://arctraining.github.io/python-2021-04/
- **Github repository** - https://github.com/ARCTraining/python-2021-04
- **Research Computing website** - https://arc.leeds.ac.uk/
## Agenda Day 1
| Time | Agenda |
| -------- | ------------------------------------------ |
| 0900 | Intro, using Google Colab, What is Python? |
| 0950 | Break |
| 1000 | Python basics, Handling data |
| 1050 | Break |
| 1100 | Python packages and Pandas |
| 1150 | Questions |
| 1200 | Close |
## Agenda Day 2
| Time | Agenda |
| -------- | ----------------------------------------------- |
| 0900 | Mount google drive onto colab, using pandas |
| 0950 | Break |
| 1000 | Indexing and subsetting, Data types and formats |
| 1050 | Break |
| 1100 | Combining dataframes |
| 1150 | Questions |
| 1200 | Close |
## Agenda Day 3
| Time | Agenda |
| -------- | ----------------------------------------------- |
| 0900 | Indexing and subsetting, Data types and formats |
| 0950 | Break |
| 1000 | Merging dataframes |
| 1050 | Break |
| 1100 | Loops and functions |
| 1150 | Questions |
| 1200 | Close |
## Agenda Day 4
| Time | Agenda |
| -------- | ----------------------------------------------- |
| 0900 | Finishing off merging, loops and functions |
| 0950 | Break |
| 1000 | loops and functions cont., plotting with plotnine|
| 1050 | Break |
| 1100 | Bringing it all together |
| 1150 | Questions |
| 1200 | Close |
## What's your name and where do you come from?
- Alex Coleman, Research Software Engineer, my research has previously been in natural language processing and clustering event descriptions data and simulating crime rates using historic data.
- Martin Callaghan - Research Computing Consultant. Bit of a 'jack of all trades' but my research area is Natural Language Processing focussing on text summarisation.
- Nick Rhodes - Research Software Engineer, background in software and systems development and support; generalist.
- Ramona Behravan - Post Doc, school of Design. I work with python on Machine Learning projects but never had the basics to build upon, just jumped right in.
- Les Arkless, technician Civil Engineering. design and coding for data loggers and image capture for expt work using Raspberry Pi's.
- Omar - just finished my PhD. Going to do some publications on my research field
- James Padgett, Systems Librarian working in IT App Support looking after Library systems including the Library Management System. I have an unnatural obsession with Python....that's why I'm here, and I like to link systems together using APIs etc.
- Sarah - PhD student, want to learn python
- Amy Turner - PhD researcher hoping to learn a bit more about how to use computational power to answer biological questions
- Will Grant - PhD student looking to learn more about programming in general, and python seemed like a good place to start.
- Thomas Watson - PhD student, looking to use Python creatively in practice-based research
- Lydia H - PhD student in ITS, i want to learn python to help me with my research as it need lots of repetitive calculation
- Alex B - Final year PhD student, which has used Python before (not very well) to automate data analysis and want to learn how to do it more efficiently.
- Raeesa - PhD student in mech eng wanting to widen skill sets to be more applicable for wider engineering applications
- Nouf - PhD student, looking to learn how to use Python before I start my project
- Amir - a PhD student of school of Electronic and Electrical Engineering.
- Charlotte, I'm just interested in learning how it works
- Sophie, Masters by Research student studying Geogrpahy. Hoping to learn some coding and see how it all works.
- Sumitra S - Postdoc, School of Biological Sciences, hoping to learn some coding to implement in my work.
- Elton Vasconcelos - Bioinformatics Research Officer @LeedsOmics
- Kristine - PhD in Mechanical Engineering just want to learn how to do programming
- Sibo-PhD student in School of Biology, hoping to learn some coding to use in my research work
- Yousef, PhD student in school of Medicine
- Muyang Zhang, PhD student in school of Maths
- Mazin Nasralla, PhD student in School of Physics and Astronomy. I want to use Python for data processing, and graphing results.
- Shradhanjali Sahu, PhD student
## Further reading
- Python notebook magic commands - https://ipython.readthedocs.io/en/stable/interactive/magics.html
- Pandas documentation - https://pandas.pydata.org/docs/
## Misc code snippets
### Using `os` to check if something is a file or folder
```python
os.path.isdir("string/file/path")
```
This returns a boolean value based on the string file path passed. True, if the file path points to a directory. False if the path points to something that isn't a directory.
```python
os.path.isfile("string/file/path")
```
Does the same for checking something is a file.
### Including LaTeX for plot text
You can use LaTeX rendering for plot text features. To do this you need to tell `matplotlib` (which `plotnine` is using) that you are using LaTeX syntax in the text elements. You can do this with the line:
```python=
from matplotlib import rc
rc('text', usetex=True)
```
A full example is:
```python=
import plotnine as p9
import pandas as pd
import numpy as np
from matplotlib import rc
rc('text', usetex=True)
df = pd.DataFrame({"x": np.random.uniform(size=10),
"y": np.random.uniform(size=10)})
(p9.ggplot(df, aes("x", "y")) +
p9.geom_point() +
p9.labs(x="$\\sum_{i = 1}^n{x_i^2}$",
y="$\\alpha + \\beta + \\frac{\\delta}{\\theta}$")
)
```
