Daily Coding Challenge 2020

On December 30th, 2019 I had an idea to start a #dailycoding challenge. The goal is to post content around the topic of coding in R and Python. Below is the comprehensive view into all 366 posts for 2020! The motivation behind this challenge was to become more proficient with programming, as well as sharing knowledge with the community.

JANUARY

Jan 1, 2020 Programming vs. Coding

Day 1 of #dailycoding challenge - Let’s start with the difference between “programming” and “coding”.

Programming involves coding, as well as analyzing and implementing algorithms, understanding data structures, problem solving, etc. It’s the process of developing executable program which performs a set of instructions.

Coding involves writing lines of code to develop a software program. It’s the process of writing code from one language to another.

Basically, all programmers = coders but not all coders = programmers.

You can think of programming as writing a book and coding as writing a chapter.

#code #program #programming #R #python #coding

Jan 2, 2020 Comments

Day 2 of #dailycoding challenge - As you are coding, it is important to leave comments throughout the script. Comments do not have an impact on your program; however, they can be really valuable to people reading your code (and for yourself when you are trying to figure out what you did). Coding languages have different symbols to signify comments.

I’m currently learning R and Python and both of these languages use the hashtag (#) to allow comments.

One tip is to only comment when necessary; over commenting can confuse people, it takes more time, and can look messy. Comments should be short, straight to the point, and informative.

Being able to comment your code efficiently is an important skill for any coder; it is something that should become a habit early on in your coding practice. Below is an example of a comment in R and Python.

#r #python #code #coding #program #programming #comment #document #overcommenting #habit #languages

 

Jan 3, 2020 Install Packages

Day 3 of #dailycoding challenge - Libraries and packages are a set of useful modules and functions that minimize the amount of code we write.

There are thousands of R and Python libraries / packages available to help coders. Installing packages is really straightforward. See image below for example how to install tidyverse for R and pandas for Python.

The libraries / packages you will need to install is highly dependent on the task you need to accomplish and your objectives.

For example, if you are looking for data visualization packages, you can consider the following:

#r #python #code #coding #program #programming #comment #library #libraries #packages #pandas #tidyverse

Jan 4, 2020 Import Data

Day 4 of #dailycoding challenge - although you are able to simply write data into R and Python, chances are there are files somewhere on your computer, or the Internet, that you would like to analyze. Let’s talk about importing data into R and Python from a local csv file.

View the image below for an example of importing a local csv (sample-superstore) as a data frame into R and Python. A data frame is an organized table with rows and columns (think spreadsheet or database table). Once you’ve imported the data, you can view the top 3 and bottom 3 rows using the head and tail functions for both R and Python. This allows you to quickly test whether the data is pulling in correctly.

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #importingdata #data #csv #pandas #dataframe

Jan 5, 2020 Motivation

Day 5 of #dailycoding challenge - my motivation behind learning to code in R & Python is to:

I spent some time this morning going through Matt Dancho’s R course - love how the content is structured and delivered; really easy to follow along. Learned about Tibbles and the glimpse() function in R.

He has a free course available - see link in comments.

What’s your motivation?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #course #free #learning #glimpse #tibbles

Jan 6, 2020 Data Joins

Day 6 of #dailycoding challenge - it would be awesome if all of the data we needed to analyze sat in a nice, clean, accessible table. The reality is that data is usually found across several databases, tables, and other sources.

Interesting insights can be uncovered when we join different data sets together…..ENTER “data joins”. There are several types of joins that you can use to merge datasets:

You can merge data from tables one-to-one or one-to-many, using a specific field or a common key between the data sets (e.g. order id, customer id, etc).

In R, you can use the pipe operator (%>%) to join tibbles (data frames). Pipes take the output from one function and feed it to the first argument of the next function. The %>% pipes together commands into chains and makes the code easier to read.

Do you use pipes?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #joins #tibbles #pipe #datajoins #join #merge #data

Jan 7, 2020 DASK

Day 7 of #dailycoding challenge - if you are using Python and working with data, chances are you use Pandas very often. Pandas is great for data loading, filtering, transformation, and general manipulation.

You might face challenges when working with BIG data. Once your data is too big to fit into memory you need to rely on extra code which slows down the computation time. Processing of big data also takes a lot of time. Another option is to scale hardware (setting up cloud clusters and leveraging Apache Spark to scale computations) which requires DevOps skills, more effort, more time, and more money.

ENTER…..DASK - > Dask attempts to address these challenges while remaining in the style and structure of Pandas.

Dask is a Python parallel computing library; it allows for rapid and efficient scaling of computations. It provides an easy way to handle BIG data in Python with minimal extra effort. You can easily replace a Pandas dataframe with Dask and Dask will take care of speeding up the computations.

Here’s a link to an awesome article on the power of Dask from Saturn Cloud - > you can even follow along with the code to witness the computation power for yourself: https://www.saturncloud.io/s/practical-guide-to-dask/

Have you used Dask? Would love to hear about your experience with it.

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #dask #computation #processing #pandas

Jan 8, 2020 Code Smell

Day 8 of #dailycoding challenge - what’s that smell? It’s “code smell”. Code smells are a set of common “sniffable” signs that code is not good and needs refactoring or needs to be cleaned up. Here are a few examples of code smells that you might encounter when reviewing code:

☞ Duplicate code - remove duplication where possible

☞ Long methods - shorter is better; refactor long methods into smaller methods if possible

☞ Feature envy - when a method does not leverage data or methods from the class it belongs to and requires lots of data or methods from a different class

☞ Data clumps - the same data hanging around together might belong together; consider rolling related data up into a larger class

☞ Dead code - delete code that isn’t being used to make it clean and simple

What other “code smell” have you encountered?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #codesmell #smell #refactoring

Jan 9, 2020 Data Types

Day 9 of #dailycoding challenge - when analyzing data, it’s important to understand the type of data you are working with. Variables can store data of different types and different types can do different things.

How do know which data type you are working with?

Below is an image that highlights some of the basic data types for R and Python.

Do you encounter all of these data types in your day-to-day analysis?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #datatypes #data #string #tuples #numeric #dataframes

Jan 10, 2020 Errors

Day 10 of #dailycoding challenge - ⚠️ ERROR…when you are just starting out (or even have experience) with coding, you will face an error; this can be intimidating, scary, and annoying!

It can take a lot of effort and time to decipher an error message so it’s good to familiarize yourself with some common errors that you might encounter when coding.

When using R, you might face these common errors:

⚠️‘could not find function’  - arises when an R package is not loaded properly or due to misspelling of the functions

⚠️‘object not found’ - occurs when the particular object used in the code is empty.

⚠️‘: cannot open the connection’ - appears when a file/connection can’t be opened because R can’t find it (mostly due to an error in the path)

When using Python, you might face these common errors:

⚠️’SyntaxError: invalid syntax’ -  caused by not following the proper structure (syntax) of the language

⚠️’IndexError’ - appears when trying to access an item at an invalid index or when index of a sequence is out of range

⚠️’MemoryError’ - raised when an operation runs out of memory

Takeaway from this post = don’t be intimidated or discouraged by errors - usually if you Google it or check on stackoverflow, you’ll quickly find a way to resolve your issues

What’s another common error you face on a regular basis?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #errors #error

Jan 11, 2020 Naming Variables

Day 11 of #dailycoding challenge - in coding, variables are used to hold and manipulate values. You can use the variables to easily access the value or object that is stored in the variable.

To assign a value to a variable all you need to do is provide a variable name and assign it a value; see below for examples:

Python - name = ‘Kate Strachnyi’] if you type in print(name) the program would return ‘Kate Strachnyi’. We’ve easily assigned the variable, name, a value of ‘Kate Strachnyi’

R - name <- ‘Kate Strachnyi’] if you type in print(name) the program would return ‘Kate Strachnyi’.

Each of the languages have specific criteria for naming variables - see image below for an overview of the criteria

What protocol do you use for naming your variables?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #variables #names #naming #reservedwords

Jan 12, 2020 GitHub

Day 12 of #dailycoding challenge - GitHub is one of the “must-use” tools when coding. It provides hosting for software development version control using Git; a distributed version-control system for tracking changes in source code during software development.

Millions of users develop millions of projects there; so you can think of it as a software factory. It also has several collaboration features such as task management, bug tracking, and feature requests.

So far, I’ve only used GitHub for storing a few files that I needed my students to be able to pull down and follow along during a Data Visualization with Tableau Workshop. Here is my GitHub: https://github.com/storybydata

I recorded a 3 minute video on GitHub a few months ago that provides an explanation of the uses of GitHub and common terminology. Link to video: https://www.youtube.com/watch?v=OVTMzMZ9Lng 

Are there any coders out there that don’t use GitHub? Do you have another way of maintaining version control?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #git #github #versioncontrol #repository

Jan 13, 2020 Typing Speed

Day 13 of #dailycoding challenge - how fast do you type? does it matter?

When you think of an expert coder or programmer, you likely picture this individual as a really FAST typer. Typing is a large part of coding - you have to write a lot of code to become an expert coder and practice usually results in improvement.  

Fast typing speed doesn’t always mean an individual is a great coder; it just implies they’ve spent a large number of hours typing and practicing the skill set. When you no longer have to hunt for the letter you are looking for, you are able to stay more focused on the task at hand -> the code you are writing and therefore, work more efficiently.

The average typing speed is around 40 wpm (words per min). I took the test myself this morning, results shown below.

There appears to be a relationship between a coders typing speed and their productivity - what are your thoughts?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #typing #speed #typingspeed #efficient #wordsperminute

Jan 14, 2020 Online Course Tips

Day 14 of #dailycoding challenge - Online courses allow learners to develop skills on their own time, from any location, at their own pace; it’s no surprise that the popularity of these courses is on the rise.

I’ve personally taken several online courses to expand my knowledge in various areas of work and life. One issue I’ve noticed with online courses is that we can fall into a few traps such as not paying attention, multitasking, etc. while watching the course  -> this is due to a lack of perceived accountability. If the instructor was standing directly in front of us, we likely would avoid multitasking or letting our mind wander.  

In the image below I highlight a few tactics that I recommend when taking online courses (specifically for coding).

I’m currently taking Matt Dancho’s R course and have applied these tactics to enhance my learning experience.

Do you have other tips for making online courses more impactful?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #tactics #onlinelearning #mooc #learning #tips

Jan 15, 2020 Loops

Day 15 of #dailycoding challenge - let’s talk about loops. Loops are used in programming to repeat a specific block of code.

Types of Loops:

Python: There are “for” loops, “while” loops, and “nested” loops. The for loops iterate for a given sequence; the while loops repeat as long as a certain Boolean condition is met, and the nested loops allow you to use one or more loop inside another while loop.

R: There are “while” loops”, “for” loops,  and “repeat” loops. While loop repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. For loops, like a while statement, except that it tests the condition at the end of the loop body. A repeat loop executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.

Do you use loops in your daily work, if yes -> what do you use them for?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #loops #for #while #repeat #iterative #work

Jan 16, 2020 Working Directory

Day 16 of #dailycoding challenge - it is important to know how to find and set your “working directory” when coding -> where the program finds all of the files for reading and writing on your computer.

You can find your working directory by using these functions:

R:

> #Getting the working directory in R

> getwd()

> #Setting the working directory in R to “dir”

> setwd(dir)

Python:

#Getting the working directory in Python

1| import os

2| os.getcwd()

#Setting the working directory in Python to “Public\\Python”

1| import os

2| os.chdir("D:\\Public\\Python\\")

Do you have any tips to share on working directories?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #workingdirectory #directories #setwed #getwd

Jan 17, 2020 Simple Calculator

Day 17 of #dailycoding challenge - who needs a calculator when you can use R or Python!

These languages can be used as powerful calculators by entering equations at the prompt. All you need to do is type in the expression and run the code; the program will evaluate the expression and respond with the result.

> 34+3

[1] 37

It’s important to learn the rules of operator precedence prior to using these functions.

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #calculator

Jan 18, 2020 Splitting Columns

Day 18 of #dailycoding challenge - sometimes the data we are working with is not in the format we need it to be for analysis. I just learned about the separate() function in R -  used to separate a character column into multiple columns using a regular expression separator

Here’s an example of splitting the column “description” into 3 columns; using  “ - “ as a separator:

#bikes_orderlines is a joined tibble

bike_orderlines_joined_tbl %>%

    # Separate description into category.1, category.2, and frame.material

    separate(description,

             into = c("category.1", "category.2", "frame.material"),

             sep = " - ",

             remove = TRUE)

   

The remove = TRUE simply means we are not going to keep the original column “description”; setting this to FALSE would include the original column in the dataframe.

In Python, the same can be done using the str.split() function.

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #split #string #separator

Jan 19, 2020 Adding Columns

Day 19 of #dailycoding challenge - sometimes we need to add columns to data frames that result from formula-style calculations of other columns.

In R, we can use the mutate() function; to add new variables and preserves existing ones.

#Example: mutate(price = units.sold * cost.per.unit) - this calculates the total price of items sold times the cost per unit.

In Python, we can use directly perform the required operation on the desired column element-wise.

#Example: df['discounted_price'] = df['Sales'] - (0.1 * df['Sales']) - this calculates the discounted price of an item (assuming a 10% discount) and adds a new column called “discounted_price”

Do you add columns to data frames using formula-style calculations?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #calculation #mutate #columns #dataframe

Jan 20, 2020 Remove Columns

Day 20 of #dailycoding challenge - we can remove unnecessary columns from a data frame.

In R, we can easily do this with the dplyr package by using the select(-“column name”) function. Just remember to add the negative sign in front of the column name.

In Python, we can do this by using the pandas library and use the:

df.drop(columns = ‘Region’))  

If you wanted to delete multiple columns you can do this:

(df.drop(columns = ['Region','Segment','Ship Date']))

ndf = (df.drop(columns = 'Region'))

Are there simpler ways to remove columns from a dataframe?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #remove #columns #dataframe #pandas #drop #select #function

Jan 21, 2020 Changing Column Names

Day 21 of #dailycoding challenge -  changing the names of column headers is a pretty straightforward task in R and Python. Below are examples of how we can change the names of column headers:

In R we can use rename(new.name = original.name) OR rename(x, replace, warn_missing = TRUE, warn_duplicated = TRUE) OR we can use set_names(x, nm = x, ...)

In Python we can use DataFrame.rename(self, mapper=None, index=None, columns=None, axis=None, copy=True, inplace=False, level=None, errors='ignore')

How do you typically address the task of renaming columns in a data frame?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #rename #columns #dataframe

Jan 22, 2020 Keyboard Shortcuts

Day 22 of #dailycoding challenge - keyboard shortcuts are great! They can help us be more efficient and speed things up when coding. See the image below for a few shortcuts you can use in R and Python. I use Windows so these shortcuts will have to be updated if you are using a Mac.

If you are using RStudio...click on Help -> Keyboard Shortcuts Help -> this will show you a list of shortcuts. In Python, if you are using Jupyter notebooks, you can see a list of shortcuts by clicking on Help -> Keyboard Shortcuts.

Are there some keyboard shortcuts that you ALWAYS use? Please share them

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #shortcuts #keyboard #efficiency

Jan 23, 2020 - Basic Data Visualization

Day 23 of #dailycoding challenge - I’m finally getting to the fun point - data visualization!

I’ve loaded some data into both R Studio and Python (Jupyter) - Superstore Data. I used R (ggplot2) to look at  “Sales by Category” - and created a bar chart. Then I used Python (matplotlib.pyplot) to create a scatterplot of Sales vs. Profit” - image below shows the code + output.

***Question for the R experts - how can I update the code (see image) to view the Sales in dollars? I know it has something to do with a mutate(sales = scale::dollar(sales)) function but I couldn’t get it to work.

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #datavisualization #ggplot2 #matplotlib #scatterplot #barchart

Jan 24, 2020 Google Dataset Search

Day 24 of #dailycoding challenge - if you want to practice your data analysis skills and need a dataset, check out Google’s Dataset Search - it just came out of beta!

Dataset Search lets you search nearly 25 million data sets; with about 2 million of those data sets coming out of U.S. government data

Some cool features of the Dataset Search include:

I tried searching for a few random things like elephants, running, and data science and found some interesting data sets. Have you used it yet?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #dataset #google #search #data

Jan 25, 2020 Makeover Monday - Sugar

Day 25 of #dailycoding challenge - today I’m attempting to create a data visualization for #makeovermonday using #R, #Python, and #Tableau. The data set includes information around free sugars intake (as a % of total energy) in all age groups over a period of time. Below is the approach I took for the three visualizations (along with the amount of time it took me):

  1. Download the Excel file and look at the rows and columns to gain familiarity with the data (3 minutes)
  2. Load the data into R, Python, and Tableau Desktop (1 minute) - there is an easy feature on the site that provides the R and Python embed codes to load the data
  3. Select the focus area for the data visualization (filtering on the latest data (2014-2015) and on further filtering on data for children. Since the recommendation is to consume no more than 5% of our calories from free sugars - I wanted to visualize the issue with children having too much sugar in their diet. (3 minutes)
  4. Draw a sketch on paper of what I want to design in the software (2 minutes)
  5. Visualize the data in Tableau, then R, then Python; started with Tableau because it’s the easiest for me! (Tableau - 3 minutes; R = 15 minutes; Python = 10 minutes)
  6. Copy paste the visualizations into PPT and request feedback

Note: I struggled BIG TIME with R - thank you so much to those that provided support. I ended up using the esquisse package - will post more on this in the future as it is AWESOME!!!

Which one do you think looks best? Any recommendations to improve these?

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #data #dataviz #datavisualization

Jan 26, 2020 Esquisse Package - Like Tableau

Day 26 of #dailycoding challenge - after some struggle with creating a bar chart in R yesterday, I was really excited to learn more about the esquisse package (thank you to Scott Kennedy for the suggestion).

Esquisse is a ‘shiny’ gadget used to create ggplot2 charts ->  interactively with drag-and-drop for mapping variables. It allows you to quickly visualize your data and export as an image or to powerpoint. You can also directly insert the code to reproduce the chart in R Studio. It can also be used as a learning tool to see what code you need to write in order to achieve the results you want. I think I like this a lot because it reminds me of Tableau!

I highly recommend you check this out for yourself. Share your thoughts on the package!

Link to video: https://www.youtube.com/watch?v=9kLmtYjiRIM&feature=youtu.be

☞ Follow the #dailycoding hashtag to see more coding posts in your newsfeed

#r #python #code #coding #program #programming #esquisse #datavisualization #data #ggplot #tutorial

Jan 27, 2020 New App Idea

Day 27 of #dailycoding challenge - really excited to share that I’ve decided to build a mobile app!

I know exactly what I want the app to do, now it’s time to figure out the details behind how to make it work.

The next step for me is to design an image for the app icon and the name - because that’s what will motivate me to develop it!

The motivation for this app came out of a personal interest (HINT - it’s something that I really look forward to on a daily basis).

I plan to document and share the entire app development journey from idea generation all the way to getting it into the App Store. Will share more info soon!

If you’ve developed an app and can share some helpful resources that would be great!

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #app #idea #appdev #appstore #development

Jan 28, 2020 Data Visualization to Raise Awareness

Day 28 of #dailycoding challenge - Using the power of data visualization to raise awareness of the Coronavirus outbreak.

As of this morning there have been 4,474 confirmed cases (mostly centered in Mainland China). Map view designed in Tableau (took ~3 minutes).

Which packages would you recommend to replicate this in R or Python?

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #data #datavisualization #tableau #dailycoding

Jan 29, 2020 Language for App Dev

Day 29 of #dailycoding challenge - the next step for me in developing an app is choosing which language to code it in. I’m debating if I should go with Python and use kivy or beeware or if I should look into something like Appy Pie which allows you to create apps without coding.

Would love to hear input on approach!

Also, I added a page to Story by Data that provides more info on the daily coding challenge

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming  #appypie #kivy #beeware

Jan 30, 2020 APP IDEA ANNOUNCEMENT

APP IDEA ANNOUNCEMENT

Day 30 of #dailycoding challenge - the day has come to announce the APP I’m building! As mentioned in an earlier post, it is important for me to have the icon + app name selected - > this serves as motivation for me to build the app.

IDEA: The app will provide alerts/ notifications a few minutes in advance of the sunrise and/or sunset in your location.

MOTIVATION: I absolutely LOVE watching the sunrise and sunset and want my phone to let me know in advance when that gorgeous view is coming my way. This will allow me to never miss the sun again!

CODE: I’m still in the research phase of how I to access the rise/set times for the sun using the phone location. Please let me know if you have recommendations.

VOTE: Please vote on the name and image that you think best represents the app - I’m between “Sun Time” and “Rise & Set”

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #app #development #suntime #riseset #sunapp #sunset #sunrise

Jan 31, 2020 Python Kivy

Day 31 of #dailycoding challenge - after thoroughly researching various programming languages for app development, I decided to go with Python. I will use Kivy - the cross-platform Python library.

Why Kivy? It runs on Linux, Windows, OS X, Android, iOS, and Raspberry Pi. You can run the same code on all supported platforms. It is 100% free to use, under an MIT license and you can use it in a commercial product. With Kivy, you can also access mobile APIs to manipulate things like the camera on a phone, the gyro sensor, GPS, vibrator, and so on.

Some of the apps built with Python include: Instagram, Pinterest, Spotify, Dropbox, Uber, Reddit.

My first step is to install Kivy; they recommend using pip install. PIP is an acronym that stands for “Preferred Installer Program”. It’s a command-line utility that allows you to install, reinstall, or uninstall packages with a simple and straightforward command: pip

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #pip #install #app #appdev

FEBRUARY

Feb 1, 2020 Running Kivy

Day 32 of #dailycoding challenge - using pip, I installed Kivy for Python. The next step is familiarizing myself with the Kivy app lifecycle (image below).

Creating a kivy application includes 1) sub-classing the App class, 2) implementing its build() method so it returns a Widget instance (the root of your widget tree), and 3) instantiating this class, and calling its run() method.

This app development stuff isn't that straightforward...

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #kivy #app #appdev

Feb 2, 2020 - Widgets

Day 33 of #dailycoding challenge - digging deeper into app development and starting to think I might not be smart enough to build an app haha - will keep trying though!

In Kivy, an application’s user interface is composed of widgets. Everything that you see on the screen is somehow drawn by a widget. A widget contains data, defines the user’s interaction with that data and draws its visual representation. A widget does exactly what its supposed to do and nothing more.

When creating an application, you have to ask yourself three important questions:

1. What data does my application process?

2. How do I visually represent that data?

3. How does the user interact with that data?

It’s important to keep these three questions in mind when you design your widgets. The goal is to write the widgets in a minimal and reusable manner.

Any tips on becoming smarter as I try to figure this stuff out?

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #app #development #kivy #widget

Feb 3, 2020 - Kivy Architectural Overview

Day 34 of #dailycoding challenge - now that I’m familiar with the use of widgets, I thought it would be useful to explore the architectural design of Kivy. The goal is to get an understanding of how everything works together. Below is an architectural overview of the building blocks; I’m taking a detailed read through how this was designed from a software engineering point of view.

Do you also try to become familiar with how things work together prior to getting into the code?

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #app #development #kivy #widget #architecture

Feb 4, 2020 - Glimpse() and info()

Day 35 of #dailycoding challenge - working with wide data (large number of columns) can become difficult. In R, if you are trying to take a look at all of the column headers in a wide data set, you can use the glimpse(df) function. This will display a vertical preview of the dataset.  

Most of the data sets I work with are considered to be “wide” so this function definitely helps me quickly review the data.

In Python - you can use the df.info() function for a similar output.

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #glimpse #info

Feb 5, 2020 Programming vs. Data Viz Tools

Day 36 of #dailycoding challenge - I created a bar chart in Python and R and showed it to someone that I work with. His reaction = I could’ve built this a lot quicker and easier in Tableau/ Power BI… He also mentioned that the visualization wasn’t the best he’s seen and asked if there are any benefits to using a programming language to visualize data.

I think there are clear benefits to using programming languages for data visualization and googled some really cool data vizzes (see image).

What are your thoughts? Should we stick to the data visualization software for this type of work or do you prefer to use Python/ R?

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #data #dataviz #datavisualization

Feb 6, 2020 Saving Figures as Images

Day 37 of #dailycoding challenge - today, I decided to have some fun and visualize parental leave in OECD data. Data analysis and visualization is what excites me most so I try to treat myself to this activity every chance I get :)

I was learning how to save the data visualizations as png files so thought I’d share with the community.

fig = plt.figure()

plt.scatter(x,y)

plt.xlabel('Paid maternity leave in weeks')

plt.ylabel('Paid parental leave in weeks')

plt.title('Parental Leave Analysis')

plt.show()

fig.savefig('Parental Leave Analysis.png')

You can also update the .png to .pdf or other formats and you’d easily update the format that way!

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #parentalleave #save #datavisualization

Feb 7, 2020 R Tips YouTube

Day 38 of #dailycoding challenge - first let me say how excited I am to see that this hashtag now has over 3,000 followers! Great to know there are so many coding enthusiasts out there.

Dec 2016 I posted a video on the Story by Data YouTube channel. It still applies today!

1. Most important tip of all – download and install R & R Studio

2. Curiosity is good for you

3. Work on a project

4. Don’t get discouraged

5. Never stop learning

6. Familiarity

7. Visualization is fun

8. Commentary

9. Grammar

10. Get to know other technologies you can use with R.

Link to video: https://www.youtube.com/watch?v=biEpLCyQiic

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #tips

Feb 8, 2020 LEN Function

Day 39 of #dailycoding challenge - how can we quickly count the number of characters in a string?

Python: The len() function

R: The nchar() function

Below is a snapshot of how this works for my name :)

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #character #len

Feb 9, 2020 Kivy Core Package

Day 40 of #dailycoding challenge - I’m back to focusing on the Sun Time app development in Kivy. The code in the core package provides several useful features:

Clock - used to schedule timer events; one-shot timers and periodic timers (I’ll need this to provide alerts)

Cache - can be used to cache something that use often using kivy class

Gesture Detection - can be used to detect various kinds of strokes (circles or rectangles); can train it to detect your own strokes

Kivy Language - used to easily and efficiently describe user interfaces

Properties - kivy property classes that link widget code with the user interface description

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #kivy #corepackage

Feb 10, 2020 UIX (Widgets & Layouts)

Day 41 of #dailycoding challenge - the UIX module in kivy contains commonly used widgets and layouts that can be reused to quickly create a user interface. What’s UIX? It’s a set of technologies that constitute a framework for building apps. The main focus of UIX is the user presentation layer of an application. In kivy, this is covered by widgets and layouts.

Widgets - user interface elements that you add to your program to provide some kind of functionality. Examples - file browser, buttons, sliders, lists, etc.

Layouts - are used to arrange widgets. There are several ready-made layouts that can be used to position widgets. Examples - grid layouts, box layouts, etc.

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #kivy #widgets #layouts

Feb 11, 2020 Kivy Modules

Day 42 of #dailycoding challenge - still focused on learning the architecture of kivy - > modules are classes that can be loaded when a Kivy application is starting. The loading of modules is managed by the config file. Currently, they include:

Modules can be used to inject functionality into your kivy program. You can also write your own modules

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #kivy #app

Feb 12, 2020 Input Events (Touches)

Day 43 of #dailycoding challenge - Kivy is able to handle most types of input: mouse, touchscreen, accelerometer, gyroscope, etc.

The class of all input events is the MotionEvent. It generates 2 kinds of events:

  1. Touch events: a motion event that contains at least an X and Y position. All the touch events are dispatched across the Widget tree.
  2. No-touch events: all the rest. For example, the accelerometer is a continuous event, without position. It never starts or stops. These events are not dispatched across the Widget tree.

There are three states a touch can be in: 1) Down - a touch is down only once, at the very

moment where it first appears, 2) Move - can be in this state for a potentially unlimited time, 3) Up - touch goes up at most once, or never - if you know the input sources your users will be using, you will know whether or not you can rely on this state being entered

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #kivy #touch #inputevents

Feb 13, 2020 Kivy Events

Day 44 of #dailycoding challenge - events are an important concept; they make it easy to build whatever behavior you want into Kivy. You would use the EventDiscpatcher class to register event types, and to dispatch them to interested parties (usually other event dispatchers). Some examples of event dispatchers are widget, animation, and clock classes.

All objects that produce events in Kivy implement the EventDispatcher which provides a consistent interface for registering and manipulating event handlers.

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #kivy #app #event #dispatcher

Feb 14, 2020 SQL - Reasons to Learn

Day 45 of #dailycoding challenge - happy Valentine’s Day! Taking a short break from studying the kivy architecture to focus on SQL.

SQL (Structured Query Language) is a special-purpose programming language that’s used to interact with databases. It works by analyzing and understanding databases consisting of fields of data within tables.

SQL is important to know for these reasons:

  1. Data mining - Using basic queries you can identify specific data at time intervals, view update events, monitor table activity, and much more
  2. Data manipulation - SQL allows you to see the exact data and how it works, you’ll have an easier time testing and manipulating the data. Furthermore, data stored in SQL is dynamic, meaning it can be modified and manipulated at any time using some basic queries.
  3. Combining data from multiple sources - SQL makes the process a breeze by supporting simple “merges” in which the specified fields or entire databases are combined.
  4. Manage large pools of data - SQL is fully equipped to manage datapools of virtually all sizes.
  5. Standard language - SQL is the standard in the industry; it’s been around since 1970s and is used in most organizations

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #sql #valentinesday

Feb 15, 2020 SQL - Basic Joins

Day 46 of #dailycoding challenge - let’s cover some basic SQL joins.

There are four basic types of SQL joins: inner, left, right, and full. The easiest and most intuitive way to explain the difference between these four types is by using a Venn diagram, which shows all possible logical relations between data sets. Let’s say we have two sets of data in our relational database: table A and table B, with some sort of relation specified by primary and foreign keys.

See the image for a depiction of the four common types of SQL joins

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #sql #joins

Feb 16, 2020 GOOD Questions

Day 47 of #dailycoding challenge - sometimes we can get stuck with the code we are working on. There are several places to go and ask questions (e.g. stack overflow). There’s definitely a correct way to ask questions.

Here’s a cool method I found called -  asking “GOOD” questions. This method can save a lot of time and help you avoid a back-and-forth conversation that typically causes conflict and confusion. Refer to the image below.

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #good #questions #stackoverflow

Feb 17, 2020 Color Scheme

Day 48 of #dailycoding challenge -  when working with data visualizations (in R, Python, Qlik, Tableau, Power Bi, etc), a common problem people run into is the use of color.

The use of color in a data visualization plays a crucial role in telling a story. It is tempting, especially as a beginner in the data visualization space, to use as much color as possible to make the visualization look “pretty”. My recommendation is to try and avoid using too many colors in the view.

It is more effective if color is used as a method to call the attention of the audience to specific points that you want to highlight in the visual. My go to is usually gray, blue, and orange. Obviously the color choice changes if there are client preferences, etc.

What are your color scheme preferences?

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #color #storytelling

Feb 18, 2020 Transposing

Day 49 of #dailycoding challenge - I remember the exact time I uncovered “transposing” - it was several years ago and I was stuck with the work I was doing at the time - the transposing saved me SO MUCH TIME. This was in Excel. I’ve since learned how to easily transpose data in business intelligence tools as well. Now I can say that I also know how to transpose in R and Python!

R = t(df)

Python = df.T or df1.transpose()

Please share if there are other ways to transpose with R / Python.

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #transpose

Feb 19, 2020 API

Day 50 of #dailycoding challenge - if you’re anything like me, you’ve heard of the term API on several occasions and have an idea of what it means. Here’s a formal definition of an API (application programming interface) -  refers to how multiple applications can interact with and obtain data from one another. APIs operate on an agreement of inputs and outputs.

*Application: These can be apps that you use on your smartphone or a software program that you use.

*Programming: Developers use APIs to write software.

*Interface: How you interact with the application.

There are public APIs and private APIs. I’m currently researching APIs as part of the Sun Time app development (I’ll need to hit up some APIs in order to make this work). My only experience to date with APIs was writing some code that used a Twitter API.

How do you use APIs?

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #API #software #app #development

Feb x, 2020

Day x of #dailycoding challenge -

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming

Feb x, 2020

Day x of #dailycoding challenge -

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming

Feb x, 2020 - A Simple Paint App

Day x of #dailycoding challenge - prior to attempting to build an app, I’m using a tutorial to build my first widget with Kivy. I’ll build a simple paint app.

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #app #development #kivy #widget

Feb x, 2020 - Pong Game Tutorial

Day x of #dailycoding challenge - prior to jumping into building the “Sun Time” app, I’m learning everything I can about app development using Kivy. I’m using a step-by-step tutorial to  build a Pong Game App. The goal is to learn the design patterns and app dev processes and to let me run the app on my OS.

Step 1 - Create a directory for the game and a file named main.py

Step 2 - Add simple graphics using a .kv file to define the look and feel of the PongGame class

Step 3 - Add a new PongBall class to create a widget that will be the ball and make it bounce around

Step 4 - Make the ball move; we can schedule any function we want using the Clock and specifying the interval

Step 5 - Adding Players and reacting to touch input; implement the on_touch_move function for the PongGame class and have it set the position of the left or right player based on whether the touch occurred on the left or right side of the screen.

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming #app #development #kivy #pong

Feb x, 2020

Day x of #dailycoding challenge -

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming

Feb x, 2020

Day x of #dailycoding challenge -

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming

Feb x, 2020

Day x of #dailycoding challenge -

☞ Follow the #dailycoding hashtag

#r #python #code #coding #program #programming

POST IDEAS

https://matplotlib.org/tutorials/introductory/usage.html#sphx-glr-tutorials-introductory-usage-py