Book Image

Artificial Intelligence with Python

Book Image

Artificial Intelligence with Python

Overview of this book

Artificial Intelligence is becoming increasingly relevant in the modern world. By harnessing the power of algorithms, you can create apps which intelligently interact with the world around you, building intelligent recommender systems, automatic speech recognition systems and more. Starting with AI basics you'll move on to learn how to develop building blocks using data mining techniques. Discover how to make informed decisions about which algorithms to use, and how to apply them to real-world scenarios. This practical book covers a range of topics including predictive analytics and deep learning.
Table of Contents (23 chapters)
Artificial Intelligence with Python
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Handling time-series data with Pandas


Let's get started by learning how to handle time-series data in Pandas. In this section, we will convert a sequence of numbers into time series data and visualize it. Pandas provides options to add timestamps, organize data, and then efficiently operate on it.

Create a new Python file and import the following packages:

import numpy as np 
import matplotlib.pyplot as plt 
import pandas as pd 

Define a function to read the data from the input file. The parameter index indicates the column number that contains the relevant data:

def read_data(input_file, index): 
    # Read the data from the input file 
    input_data = np.loadtxt(input_file, delimiter=',') 

Define a lambda function to convert strings to Pandas date format:

    # Lambda function to convert strings to Pandas date format 
    to_date = lambda x, y: str(int(x)) + '-' + str(int(y)) 

Use this lambda function to get the start date from the first line in the...