Posts

Understanding np.where and its Applications in Pandas

Image
NumPy's np.where function is a versatile tool that can be used for conditional execution. It's especially handy when working with large datasets in pandas DataFrame or Series objects. In this post, we'll unravel the use of np.where in a real-life data manipulation task involving a movie dataset. Here's a code snippet we'll be discussing (Google Colab Interactive Example ): ************************Code Snippet*******************************; import pandas as pd import numpy as np loc = 'https://raw.githubusercontent.com/aew5044/Python---Public/main/movie.csv' m = pd.read_csv(loc) m1 = (     m     .assign(color = lambda x: x.color.fillna('Missing')) #Fill in missing values with "Missing"     .assign(bw = lambda x: np.where(x.color != 'Color', 1, 0)) #Create a new column called "bw"     .assign(bw_after_1939 = lambda x: np.where((x.title_year > 1939) & (x.color.str.startswith('B') | x.color.str.startswith('...

Update to Pandas 2.x

 I have found success in updating to pandas 2.x by first installing pandas with conda then updating the version with pip.  Here are my steps: Create the environment conda create --name movies Activate the environment conda activate movies Install Pandas and Numpy conda install pandas numpy pip Upgrade pandas to a specific version pip install --upgrade pandas==2.0.1 Those are the steps to get get a new environment, download the basic packages, and then install pandas 2.0.1. 

Creating and Setting Up a New Conda Environment for Data Analysis

  Here's a brief blog post on how to create a new Conda environment called "movies", activate it, and then install the Pandas and NumPy libraries. Conda is a popular, open-source package management system that simplifies setting up environments and installing libraries for Python. Today, we're going to walk through how to create a new Conda environment, activate it, and install some essential data analysis libraries - Pandas and NumPy. Step 1: Install MiniConda  First things first, ensure you have MiniConda installed on your machine. If not, you can download it from the [official MiniConda page](https://docs.conda.io/en/latest/miniconda.html). Follow the instructions specific to your operating system to get it set up. Step 2: Create a New Conda Environment Once you have MiniConda installed, open up your terminal or command prompt. To create a new environment, we use the `conda create` command followed by `--name` and then the name of the environment. For this example,...

Plotly Bar Chart

 Coming from an analyst background, I have been making bar charts for years.  So, this example is not very interesting.  However, it shows the simplicity of plotly express and how easily one can create a bar graph.  I didn’t stray far from the path regarding the official plotly example.  It is their example.  However, I wanted to show how easy it is to get going.  The only thing I modified was the graphic size in Google Colab.  Very easy and approachable! import plotly.express as px long_df = px . data . medals_long () fig.update_layout( width=800, #set the width of the plot to 800 pixels height=500, #set the height of the plot to 500 pixels ) fig = px . bar ( long_df , x = "nation" , y = "count" , color = "medal" , title = "Long-Form Input" ) fig . show ( fig = px.bar(filtered_df, x="nation", y="count", color="medal", title="Long-Form Input") fig.show() The full example is located at:...

Plotly Adventure

My goal is to learn new packages related to visualizations and dashboarding with python.  An overwhelming vote by the internet says, "learn plotly!" As a result, I asked GPT-4, what are things to know about plotly, and this is the response. I plan to follow each section and provide a post diving into each topic.  As an experienced programmer with years of experience with Plotly, I would guide you through the main principles and learning steps as follows: Introduction to Plotly : Plotly is an open-source graphing library that makes it easy to create interactive, publication-quality visualizations in Python, R, and other programming languages. It provides a high-level interface for drawing attractive and informative statistical graphics. Understanding Plotly components : Familiarize yourself with the core components of Plotly, such as Plotly Express (a high-level interface for creating common chart types quickly) and Graph Objects (a low-level interface for more customizable ch...

North Carolina University List

Image
  I needed a list of public universities in North Carolina. What does anyone do? Start Googling. The first return was a Wikipedia page. I clicked on it and saw this beautiful table with all the information I wanted. Then I remembered there is a great method in python and pandas to pull tables from websites very easily. All I need to do is use read_html and sort the data after that. Below is a short description for each step. This code uses the Python programming language and the pandas library to read a table from a Wikipedia page about colleges and universities in North Carolina. The code begins by importing the pandas library and assigning the URL of the Wikipedia page to a variable called URL. Next, the pd.read_html() function is used to read the HTML table from the URL and return a list of tables. The first table in the list is selected using tables[0] and assigned to a new variable called df. The .query() method is then used to filter the rows of the DataFram...

Report Lab Introduction

During the past weekend, my task involved developing a report using Excel. This report, ultimately converted into a PDF, encompassed three tables, footnotes, titles, and graphics. The fulfillment of this task involved liaising with various individuals who furnished me with a summary of financial report data. I proceeded to transfer this data into an Excel spreadsheet to generate the report. While the entire operation was simple and direct, my interest was piqued to explore a new Python package. After some initial exploration, I chose to delve into the world of reportlab. Reportlab is a Python library utilizing an x and y coordinate-based layout system. Essentially, this implies that the page layout is dictated by points, with one inch containing 72 points. The page's bottom-left corner is demarcated as x = 0 and y = 0. If one desires to insert an item halfway up an 8.5 by 11-inch page, x = 612 / 2 or x=305 can be used. Furthermore, it provides a float-based system, which proves mor...