<jupyter_start><jupyter_text>Python Pandas 01 This Python program show the basic functionality of Pandas, which is a Python Data Analysis Library. Here, we use Pandas to construct a one dimensional Series and see some of the features that can be obtained. The data was generated within the Python code that represents maximum temperature every day for about a week.<jupyter_code>import os
import sys
import pandas as pd
import numpy as np
import random
import collections
import matplotlib.pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>The above shows the Python modules that have been imported. Other than the regular ones, we import `random`, which is a pseudo-random generator and `collections`, which is a specialised data type providing alternative to Python's built-in containers such as `list`, `dict`, etc.<jupyter_code># Function
def tempFunction(ld):
	i = 0
	while i < ld:
		i = i + 1
		temp = random.randrange(20, 40, 2)
		tempDays.append(temp)
	return temp<jupyter_output><empty_output><jupyter_text>This is the function, which generates the pseudo-random numbers between 20 to 40, which in our case represent the maximum temperature for a particular day. The number generated are with respect to the total number of days present.<jupyter_code># Some essential lists
tempDays = []
days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
lenDays =  len(days)<jupyter_output><empty_output><jupyter_text>Here, we generate a empty an empty `list` to store the temperature values and `days` having seven days of the week.<jupyter_code># Calling the temperature function to generate random temperatures
tempFunction(lenDays)
# Creating a ordered dictionary
tempData = collections.OrderedDict(zip(days, tempDays))
print tempData<jupyter_output>OrderedDict([('Mon', 26), ('Tue', 20), ('Wed', 34), ('Thu', 30), ('Fri', 26), ('Sat', 34), ('Sun', 26)])<jupyter_text>Note that we create a ordered dictionary using `collections.OrderedDict`. Using the Python's in-built `dict` would generate a non-orderely dictionary<jupyter_code># Creating a Pandas Series
data = pd.Series(tempData)
print type(data)
print type(data.values)
data<jupyter_output><class 'pandas.core.series.Series'>
<type 'numpy.ndarray'><jupyter_text>The above shows the generation of `Pandas Series`, where the type of data shown as `Pandas core` and the values are nothing but `numpy` `nd array`.<jupyter_code># Specifying the names to the Pandas Series
data.name = 'Temperature'
data.index.name = 'Weekday'
print data<jupyter_output>Weekday
Mon        26
Tue        20
Wed        34
Thu        30
Fri        26
Sat        34
Sun        26
Name: Temperature, dtype: int64<jupyter_text>This allows us to define a name for `Pandas Series`, including the indices.<jupyter_code># Calculating some statistics of temperature
print "Maximum weekly temperature:", data.max()
print "Minumim weekly temperature:", data.min()
print "Weekly mean temperature:", data.median()<jupyter_output>Maximum weekly temperature: 34
Minumim weekly temperature: 20
Weekly mean temperature: 26.0<jupyter_text>This shows some of the basic data analysis that can be obtained using Pandas. We have identified the maximum, minimum and mean temperatures from our data.<jupyter_code>plt.plot(data, marker='o', linestyle='-', color='r')
plt.xlabel('Days [Index]')
plt.ylabel('Temperature [C]')
plt.title('Temperature variation over a period of one week')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09332562843108928, 'fraction_numerical': 0.01444669170759896, 'mean_word_length': 5.581749049429658, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '481270', 'license': 'CNRI-Python', 'n_tokens_mistral': 1078, 'n_tokens_neox': 996, 'n_words': 411, 'path': 'Python-Pandas-01.ipynb', 'repo_name': 'deepakramanath/Python-Pandas-01', 'size': '3461'}