<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Harish Garg</title>
    <description>The latest articles on Forem by Harish Garg (@harishkgarg).</description>
    <link>https://forem.com/harishkgarg</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F97036%2Fb7765f1a-b5ef-4ae9-aab3-7459ca0ca697.jpg</url>
      <title>Forem: Harish Garg</title>
      <link>https://forem.com/harishkgarg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/harishkgarg"/>
    <language>en</language>
    <item>
      <title>How to get access to OpenAI GPT-3 API?</title>
      <dc:creator>Harish Garg</dc:creator>
      <pubDate>Thu, 25 Feb 2021 15:37:14 +0000</pubDate>
      <link>https://forem.com/harishkgarg/how-to-get-access-to-openai-gpt-3-api-3ihk</link>
      <guid>https://forem.com/harishkgarg/how-to-get-access-to-openai-gpt-3-api-3ihk</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;OpenAI has opened up its GPT-3 AI model for commercial and research uses. They have done it by the way of an API. &lt;/p&gt;

&lt;p&gt;Having OpenAI API access is necessary for doing any kind of work using OpenAI GPT-3. This API is currently in Private Beta and hence not everyone gets immediate access or sometimes no access at all.&lt;/p&gt;

&lt;p&gt;For people who want to build something with OpenAI API, getting access is like having Early Christmas.&lt;/p&gt;

&lt;p&gt;In this chapter, I am sharing the OpenAI official process to get access to their GPT-3 API as well as some best practices that have helped multiple people in getting access faster.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tR74ba1B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ni637m84gpn56y5p7yq7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tR74ba1B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ni637m84gpn56y5p7yq7.png" alt="OpenAI Access Social Proof"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Apply for Access to OpenAI API?
&lt;/h2&gt;

&lt;p&gt;To apply for access to the OpenAI API, you need to fill and submit a form available here - &lt;a href="https://share.hsforms.com/1Lfc7WtPLRk2ppXhPjcYY-A4sk30"&gt;https://share.hsforms.com/1Lfc7WtPLRk2ppXhPjcYY-A4sk30&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x0BKbYoh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t1i6z2suyhiib04h08il.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x0BKbYoh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t1i6z2suyhiib04h08il.png" alt="OpenAI Access Form"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once, the form is submitted, somebody at OpenAI manually reviews your application and decides on the access approval.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices while applying
&lt;/h2&gt;

&lt;p&gt;There are lots of people complaining online that they have applied months or weeks in the past and never received their access or OpenAI should make access to the API available. &lt;/p&gt;

&lt;p&gt;I applied for access two times. First time in July 2020. I never got access. I re-applied again in Jan and got access the very next day. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Cb_daset--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gxlytb5olixt2ubni68p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Cb_daset--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gxlytb5olixt2ubni68p.png" alt="OpenAI API Approval"&gt;&lt;/a&gt;&lt;br&gt;
While it's OpenAI 's own decision to who and how they give access to their API, there are few things one can do to speed up the approval process. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If possible and if you have access to, use an email id that is either your work email or on a domain that you own. For example, yourname@companyname or yourname@yourwebsite is better than something like &lt;a href="mailto:yourname@gmail.com"&gt;yourname@gmail.com&lt;/a&gt;. There is no official rule against using generic email services. However, in my own experience and after speaking to other people who applied, custom domain email ids have better
&lt;/li&gt;
&lt;li&gt;Try not to use non-personal email ids like &lt;a href="mailto:contact@companyname.com"&gt;contact@companyname.com&lt;/a&gt;, etc. Instead use email ids that have your name in them, like &lt;a href="mailto:harish@harishgarg.com"&gt;harish@harishgarg.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Use real person names in the Name fields, not company names or generic names.&lt;/li&gt;
&lt;li&gt;Do mention your interesting idea in the given field. Note that you don't necessarily have to build this exact idea. This particular answer tells them whether you have thought through enough before applying for access. Try coming up with an idea for an app or a project before applying.&lt;/li&gt;
&lt;li&gt;Choose one of these options.

&lt;ul&gt;
&lt;li&gt;Build a new product&lt;/li&gt;
&lt;li&gt;Integrate within existing product&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;You should fill in as many fields as possible, even if they are not mandatory. Also, do not misrepresent yourself in any of the answers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Applied for OpenAI access but still haven't received it
&lt;/h2&gt;

&lt;p&gt;Even after doing all this, if your access is taking too much time(&amp;gt; week at this moment), Here are few things you could to try speed up your access request approval.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Try sending an email to &lt;a href="mailto:support@openai.com"&gt;support@openai.com&lt;/a&gt; making your case for fast track access.&lt;/li&gt;
&lt;li&gt;Reach out to OpenAI employees on Twitter via DMs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Applying for Research Purpose.
&lt;/h2&gt;

&lt;p&gt;The above application process was decribed based on assumption that you are applying to build a product with OpenAI API. However, if your purpose is research, they have a separate application process and available on this link - &lt;a href="https://share.hsforms.com/1b-BEAq_qQpKcfFGKwwuhxA4sk30"&gt;https://share.hsforms.com/1b-BEAq_qQpKcfFGKwwuhxA4sk30&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;I would love to hear from you about your experience with getting access to the OpenAI API via &lt;a href="//harish@harishgarg.com"&gt;email&lt;/a&gt; or &lt;a href="https://twitter.com/harishkgarg"&gt;Twitter DM&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This chapter is part of the Definite Guide to building products with OpenAI API that I am writing in public and making it available for &lt;a href="https://harishgarg.com/writing/definite-guide-to-building-products-with-openai/"&gt;reading online&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;This guide is also available in formats suitable for Book Reading Apps and Devices(PDF, ePub, Kindle). If you like and want to support this work, you can Pre-Order it from one of these places.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://flurly.com/p/gpt-3-guide"&gt;Flurly&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://gum.co/gpt-3-guide"&gt;Gumroad&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://learnetto.com/users/harishgarg/courses/definite-guide-to-building-products-with-openai/"&gt;Learnetto&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>openai</category>
      <category>gpt3</category>
    </item>
    <item>
      <title>Getting back to Dev.to after two years. </title>
      <dc:creator>Harish Garg</dc:creator>
      <pubDate>Fri, 02 Oct 2020 22:02:39 +0000</pubDate>
      <link>https://forem.com/harishkgarg/getting-back-to-dev-to-after-two-years-2kb6</link>
      <guid>https://forem.com/harishkgarg/getting-back-to-dev-to-after-two-years-2kb6</guid>
      <description>&lt;p&gt;My last post here was two years back. A lot have changed since then. I will be posting more regularly here from now on.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Dev.to "Publishing from RSS" not working for me</title>
      <dc:creator>Harish Garg</dc:creator>
      <pubDate>Sun, 16 Sep 2018 04:07:14 +0000</pubDate>
      <link>https://forem.com/harishkgarg/devto-publishing-from-rss-not-working-for-me-2f1a</link>
      <guid>https://forem.com/harishkgarg/devto-publishing-from-rss-not-working-for-me-2f1a</guid>
      <description>&lt;p&gt;I setup my Dev.to profile to publish posts from my blog feed - &lt;a href="https://bignumworks.com/feed.xml"&gt;https://bignumworks.com/feed.xml&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, it Dev.to is not importing the posts.&lt;/p&gt;

&lt;p&gt;Am I missing something?&lt;/p&gt;

</description>
      <category>help</category>
    </item>
    <item>
      <title>Getting started with Bitcoin Using Python</title>
      <dc:creator>Harish Garg</dc:creator>
      <pubDate>Fri, 07 Sep 2018 02:47:26 +0000</pubDate>
      <link>https://forem.com/harishkgarg/getting-started-with-bitcoin-using-python-287o</link>
      <guid>https://forem.com/harishkgarg/getting-started-with-bitcoin-using-python-287o</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we are going to introduce Bitcoin using Python. We&lt;br&gt;
will be using Python’s &lt;a href="https://pypi.python.org/pypi/bitcoin"&gt;&lt;em&gt;bitcoin&lt;/em&gt;&lt;/a&gt;&lt;br&gt;
library, conveniently called bitcoin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To get started with Bitcoin using Python, we need,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A Computer which can run Python programming environment&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A basic knowledge of Python or another scripting language&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ability to run commands and programs from a command line program&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setup your Computer
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Install Python
&lt;/h3&gt;

&lt;p&gt;Download and install python from&lt;br&gt;
&lt;a href="http://www.python.org/"&gt;&lt;em&gt;http://www.python.org/&lt;/em&gt;&lt;/a&gt; Make sure to download&lt;br&gt;
the Python 3.x as that’s the one we are going to be using in this&lt;br&gt;
tutorial.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install bitcoin python library
&lt;/h3&gt;

&lt;p&gt;After you finish installing Python, open your command line program and&lt;br&gt;
execute below command to install bitcoin python library&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;pip install bitcoin&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Hello Bitcoin - Generate a Private key
&lt;/h2&gt;

&lt;p&gt;We will start with a writing a “Hello World” equivalent of Bitcoin in&lt;br&gt;
Python. To write your python, you can need a code or text editor which&lt;br&gt;
supports writing in ASCII format. You cannot use MS Word of Wordpad for&lt;br&gt;
this. You could use Notepad, but we recommend using &lt;a href="https://atom.io/"&gt;&lt;em&gt;Atom Code&lt;br&gt;
Editor&lt;/em&gt;&lt;/a&gt;, a free code editor.&lt;/p&gt;

&lt;p&gt;Open your favorite editor and type in below code. In this code, we are&lt;br&gt;
first importing the bitcoin library. We are then generating a private&lt;br&gt;
key using &lt;strong&gt;&lt;em&gt;random_key&lt;/em&gt;&lt;/strong&gt; function and we are then displaying the&lt;br&gt;
private key on the screen.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;from bitcoin import *&lt;/p&gt;

&lt;p&gt;my_private_key = random_key()&lt;/p&gt;

&lt;p&gt;print(my_private_key)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Save it as a .py file and then open your command line program and run&lt;br&gt;
the above program like this.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;python &amp;lt;program location and name&amp;gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This will print out a private key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generate a Public Key
&lt;/h2&gt;

&lt;p&gt;Next we generate a public key. We do this by passing the private key we&lt;br&gt;
generated to &lt;strong&gt;&lt;em&gt;privtopub&lt;/em&gt;&lt;/strong&gt; function&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;from bitcoin import *&lt;/p&gt;

&lt;p&gt;my_private_key = random_key()&lt;/p&gt;

&lt;p&gt;my_public_key = privtopub(my_private_key)&lt;/p&gt;

&lt;p&gt;print(my_public_key&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Create a bitcoin address
&lt;/h2&gt;

&lt;p&gt;In the previous programs we generated private and public keys. Now, we&lt;br&gt;
are going to real bitcoin part. In the below code, we are generating a&lt;br&gt;
bitcoin address by passing the public key we generated to&lt;br&gt;
&lt;strong&gt;&lt;em&gt;pubtoaddr&lt;/em&gt;&lt;/strong&gt; function.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;from bitcoin import *&lt;/p&gt;

&lt;p&gt;my_private_key = random_key()&lt;/p&gt;

&lt;p&gt;my_public_key = privtopub(my_private_key)&lt;/p&gt;

&lt;p&gt;my_bitcoin_address = pubtoaddr(my_public_key)&lt;/p&gt;

&lt;p&gt;print(addr)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Create a Multi-signature Address
&lt;/h2&gt;

&lt;p&gt;Next, we create a multi-signature bitcoin address. Multi-signature&lt;br&gt;
address is an address that is associated with more than one private key.&lt;br&gt;
So, we first create 3 public and private keys. We then create a&lt;br&gt;
multi-sig by passing the 3 public keys to &lt;strong&gt;&lt;em&gt;mk_multisig_script&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
function. Finally, the resulting multi-sig is passed to &lt;strong&gt;&lt;em&gt;scriptaddr&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
function to create the multi signature bitcoin address.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;from bitcoin import *&lt;/p&gt;

&lt;p&gt;my_private_key1 = random_key()&lt;/p&gt;

&lt;p&gt;print('Private Key 1: ' + my_private_key1)&lt;/p&gt;

&lt;p&gt;my_public_key1 = privtopub(my_private_key1)&lt;/p&gt;

&lt;p&gt;print('Public Key 1: ' + my_public_key1)&lt;/p&gt;

&lt;p&gt;my_private_key2 = random_key()&lt;/p&gt;

&lt;p&gt;print('Private Key 2: ' + my_private_key2)&lt;/p&gt;

&lt;p&gt;my_public_key2 = privtopub(my_private_key2)&lt;/p&gt;

&lt;p&gt;print('Public Key 2: ' + my_public_key2)&lt;/p&gt;

&lt;p&gt;my_private_key3 = random_key()&lt;/p&gt;

&lt;p&gt;print('Private Key 3: ' + my_private_key3)&lt;/p&gt;

&lt;p&gt;my_public_key3 = privtopub(my_private_key3)&lt;/p&gt;

&lt;p&gt;print('Public Key 3: ' + my_public_key3)&lt;/p&gt;

&lt;p&gt;my_multi_sig = mk_multisig_script(my_private_key1,&lt;br&gt;
my_private_key2, my_private_key3, 2,3)&lt;/p&gt;

&lt;p&gt;my_multi_address = scriptaddr(my_multi_sig)&lt;/p&gt;

&lt;p&gt;print('Multi-Address: ' + my_multi_address)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  View address transaction history
&lt;/h2&gt;

&lt;p&gt;We can also look at pre-existing bitcoin addresses’ transactional&lt;br&gt;
history. We do this passing a valid bitcoin address to function&lt;br&gt;
&lt;strong&gt;&lt;em&gt;history&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;from bitcoin import *&lt;/p&gt;

&lt;p&gt;print(history(a_vaid_bitcoin_address))&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you don’t have an address, you can look one up from&lt;br&gt;
&lt;a href="https://blockchain.info"&gt;&lt;em&gt;Blockchain&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we introduced bitcoin with python. We saw how to get&lt;br&gt;
setup with python for bitcoin. We saw how to generate private key,&lt;br&gt;
public key and a bitcoin address. We also saw how to create a multi&lt;br&gt;
signature bitcoin address and how to look at transactional history of a&lt;br&gt;
bitcoin address.&lt;/p&gt;

&lt;p&gt;If you would like to dig deeper into Bitcoin and Blockchain Concepts using Python, check it out my &lt;a href="https://www.packtpub.com/application-development/getting-started-python-bitcoin-programming-video"&gt;Video Course on Packt&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>bitcoin</category>
      <category>blockchain</category>
    </item>
    <item>
      <title> How to Analyze time series data in Python pandas</title>
      <dc:creator>Harish Garg</dc:creator>
      <pubDate>Tue, 04 Sep 2018 09:20:29 +0000</pubDate>
      <link>https://forem.com/harishkgarg/-how-to-analyze-time-series-data-in-python-pandas-ih9</link>
      <guid>https://forem.com/harishkgarg/-how-to-analyze-time-series-data-in-python-pandas-ih9</guid>
      <description>

&lt;h3&gt;Note: This post was originally published on &lt;a href="https://bignumworks.com"&gt;https://bignumworks.com&lt;/a&gt;
&lt;/h3&gt;

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;In this article, we will explore how to analyze time series data with Python's Pandas Data Analysis library. &lt;/p&gt;

&lt;p&gt;Let's first understand what we mean by Time Series data. In simple terms, time series represent a set of observations taken over a period of time. It occurs whenever the data is recorded on a regular basis. For example...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nb1rXVV1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xux99p7pziz598v5pwg1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nb1rXVV1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xux99p7pziz598v5pwg1.png" alt="test"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we have a Sales data recorded over months for multiple locations.&lt;/p&gt;

&lt;p&gt;Time series data analysis is extremely important for making informed  business and policy decisions and plans. It is used to &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;find out the past trends&lt;/li&gt;
&lt;li&gt;use the past trends to forecast current future trends.&lt;/li&gt;
&lt;li&gt;find out cyclic variations &lt;/li&gt;
&lt;li&gt;discover seasonal variations &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, a retailer can discover the seasonal and cyclic sales trends of it's inventory and plan accordingly.&lt;/p&gt;

&lt;h3&gt;Our Methodology&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;We will start with importing the necessary python modules. &lt;/li&gt;
&lt;li&gt;And then we will read in a dataset having time series data. &lt;/li&gt;
&lt;li&gt;We will transform the data to make sure it is indexable on the time series data column. &lt;/li&gt;
&lt;li&gt;We will then demonstrate how to select and filter data based on date and time. &lt;/li&gt;
&lt;li&gt;And finally we will visualize the time series data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Setting up your machine&lt;/h2&gt;

&lt;p&gt;For the code demo in this article, we are using Python 3.x and Python modules Pandas and matplotlib. We are using Pandas for reading in the data and data analysis and matplotlib for data visualization. The best way to get all the required is by installing &lt;a href="https://www.continuum.io/downloads"&gt;Anaconda Data Science Python Districtuion&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Importing Python Modules&lt;/h2&gt;

&lt;p&gt;We start with importing Pandas, matplotlib and datetime modules. We are importing datetime module for as we would need to use some of it's methods. We are also setting &lt;code&gt;matplotlib inline&lt;/code&gt; to make sure the plots are shown right in the Jupyter Notebook&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;
&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;matplotlib&lt;/span&gt; &lt;span class="n"&gt;inline&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pyplot&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;Introducing our dataset&lt;/h2&gt;

&lt;p&gt;For this code demo, we are creating a sample employees dataset with two columns&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Date field&lt;/li&gt;
&lt;li&gt;No of Employees &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This data is a quarterly count of employees from last 8 quarters.&lt;/p&gt;

&lt;p&gt;We create a data dictionary with columns names a keys and records as the values. We then pass this &lt;code&gt;dict&lt;/code&gt; object to Pandas &lt;code&gt;DataFrame&lt;/code&gt; method and create a DataFrame where this data will be stored in tabular format. &lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;'Date'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'2015-09-30'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'2015-12-31'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'2016-03-31'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'2016-06-30'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
                 &lt;span class="s"&gt;'2016-09-30'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'2016-12-31'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'2017-03-31'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'2017-06-30'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="s"&gt;'Employees'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;26&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;26&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DataFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;columns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Date'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'Employees'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, we have our data in a Pandas DataFrame, let's print it out to see how it looks.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         Date  Employees
0  2015-09-30          9
1  2015-12-31         15
2  2016-03-31         26
3  2016-06-30         15
4  2016-09-30         15
5  2016-12-31         14
6  2017-03-31         26
7  2017-06-30         25
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;As we can see, we have the data with two columns Date and Employees. Also, notice that there is a numeric row index which has been set automatically while importing data into a DataFrame. We would have to change this later.&lt;/p&gt;

&lt;h2&gt;Pandas Time and Date methods&lt;/h2&gt;

&lt;p&gt;let's get some information about the dataset, like datatypes of the column&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;class 'pandas.core.frame.DataFrame'&amp;gt;
RangeIndex: 8 entries, 0 to 7
Data columns (total 2 columns):
Date         8 non-null object
Employees    8 non-null int64
dtypes: int64(1), object(1)
memory usage: 136.0+ bytes
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We see that the date column is object, which means it's stored as text. Date time data in text format in not very useful for running time series analysis. We need to first convert this to a datetime datatype&lt;/p&gt;

&lt;p&gt;We do this conversion by calling Pandas &lt;code&gt;to_datetime&lt;/code&gt; method on the date column. We assign the converted date column back to the original Pandas DataFrame, thereby replacing the old text date column with the new datetime type column. &lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Date'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to_datetime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Date'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We check the conversion to a datetime datatype by calling the info method again on our DataFrame&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;class 'pandas.core.frame.DataFrame'&amp;gt;
RangeIndex: 8 entries, 0 to 7
Data columns (total 2 columns):
Date         8 non-null datetime64[ns]
Employees    8 non-null int64
dtypes: datetime64[ns](1), int64(1)
memory usage: 168.0 bytes
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And we see that the date column now shows up as datetime datatype.&lt;/p&gt;

&lt;p&gt;There is one more thing we need to do before we can start exploring the time series properties. We need to setup the index of our DataFrame to the date column. We do this by calling index on the Pandas DataFrame and assigning it the date series. We also delete the date column as we don't need it separately from the index.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Date'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;del&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Date'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let's print out the DataFrame to see how it looks after setting index to date column&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;            Employees
Date                 
2015-09-30          9
2015-12-31         15
2016-03-31         26
2016-06-30         15
2016-09-30         15
2016-12-31         14
2017-03-31         26
2017-06-30         25
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2&gt;Querying time series data&lt;/h2&gt;

&lt;p&gt;Now we are set to start exploring our time series data. We will start with showing some data querying techniques. &lt;/p&gt;

&lt;p&gt;Here we are querying and filtering the data and selecting only those records that are from year 2016&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'2016'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table class="dataframe"&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;&lt;/th&gt;
      &lt;th&gt;Employees&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;th&gt;Date&lt;/th&gt;
      &lt;th&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;th&gt;2016-03-31&lt;/th&gt;
      &lt;td&gt;26&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;th&gt;2016-06-30&lt;/th&gt;
      &lt;td&gt;15&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;th&gt;2016-09-30&lt;/th&gt;
      &lt;td&gt;15&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;th&gt;2016-12-31&lt;/th&gt;
      &lt;td&gt;14&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Notice that due to our converting the Date column to datetime and setting it as index, we can run all kinds of queries. Above we just passed 2016 and Pandas understood that we are looking for records from year 2016. &lt;/p&gt;

&lt;p&gt;Next we are selecting all records from June 2016 onwards.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2016&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;):]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table class="dataframe"&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;&lt;/th&gt;
      &lt;th&gt;Employees&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;th&gt;Date&lt;/th&gt;
      &lt;th&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;th&gt;2016-06-30&lt;/th&gt;
      &lt;td&gt;15&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;th&gt;2016-09-30&lt;/th&gt;
      &lt;td&gt;15&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;th&gt;2016-12-31&lt;/th&gt;
      &lt;td&gt;14&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;th&gt;2017-03-31&lt;/th&gt;
      &lt;td&gt;26&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;th&gt;2017-06-30&lt;/th&gt;
      &lt;td&gt;25&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;Time Series data visualized&lt;/h2&gt;

&lt;p&gt;Here we are using time series to visualize our data by calling the plot method on the DataFrame. Since, we have time series already set as index, we had to simply call the plot method in it's simplest form to get this plot.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;plot&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sr6hD9tO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/tkohn1pstcz8s36ikky8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sr6hD9tO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/tkohn1pstcz8s36ikky8.png" alt="png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;We touch on some of the Pandas time series data analysis capabilities. We transformed and manipulated a dataset containing time series data. We converted it to proper times series format using Pandas in-built methods. We then learned how to explore and filter the data using Pandas date time data methods and functionality. Finally, we saw an easy way to visualize time series data&lt;/p&gt;


</description>
      <category>python</category>
      <category>pandas</category>
      <category>dataanalysis</category>
    </item>
    <item>
      <title>Using Excel with pandas</title>
      <dc:creator>Harish Garg</dc:creator>
      <pubDate>Thu, 30 Aug 2018 09:33:44 +0000</pubDate>
      <link>https://forem.com/harishkgarg/using-excel-with-pandas-4b1d</link>
      <guid>https://forem.com/harishkgarg/using-excel-with-pandas-4b1d</guid>
      <description>

&lt;p&gt;I wrote a post about Using Python Pandas with Excel files for Data Analysis. Check it out - &lt;a href="https://www.dataquest.io/blog/excel-and-pandas/"&gt;https://www.dataquest.io/blog/excel-and-pandas/&lt;/a&gt;&lt;/p&gt;


</description>
      <category>python</category>
      <category>pandas</category>
      <category>excel</category>
      <category>dataanalysis</category>
    </item>
  </channel>
</rss>
