<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 T. Martz-Oberlander, 2015-11-12, CO2 and Speed of Sound
Formatting PITCH pipe organ data for Python operations
The entire script looks for mathematical relationships between CO2 concentration changes and pitch changes from a pipe organ. This script uploads, cleans data and organizes new dataframes, creates figures, and performs statistical tests on the relationships between variable CO2 and frequency of sound from a note played on a pipe organ.
This uploader script
Step1:  Uploaded data into Python¶
First I upload my data sets. I am working with two
Step2:  Next
1. Find the average pitch value for each date_time, plus standard error/deviation
2. Select out the pitch data for one division at a time. Make an argument
3. Append other pitch files
I have pitch and I have CO2. I want to make a continuous chart of CO2 over time with expected pitch, then plot measured pitch points over that to see if changes in CO2 affect how close the predicted to measured pitch values are.  
How do I generalize the column labels so I can use this script for a file with different number of freq measurements?
Step3:  These data points can be plotted on top of a calculated pitch line
Step4:  I now have an input (raw file) and output (section-selected measured pitch dataframe). This output can be called into my next script, the "env_data.py" file, for comparision between measured and calculated pitch (calculated pitch is calculated from environmental data).
Visualize pitch
Here I make a plot of changed in frequency of the C5 note over time to see if pitch is changing at all, irespective of other environmental variables. (the C note one octave above middle C).
<ASSISTANT_TASK:>
Python Code:
# I import useful libraries (with functions) so I can visualize my data
# I use Pandas because this dataset has word/string column titles and I like the readability features of commands and finish visual products that Pandas offers
import pandas as pd
import matplotlib.pyplot as plt
import re
import numpy as np
%matplotlib inline
#I want to be able to easily scroll through this notebook so I limit the length of the appearance of my dataframes 
from pandas import set_option
set_option('display.max_rows', 10)
Explanation: T. Martz-Oberlander, 2015-11-12, CO2 and Speed of Sound
Formatting PITCH pipe organ data for Python operations
The entire script looks for mathematical relationships between CO2 concentration changes and pitch changes from a pipe organ. This script uploads, cleans data and organizes new dataframes, creates figures, and performs statistical tests on the relationships between variable CO2 and frequency of sound from a note played on a pipe organ.
This uploader script:
1) Uploads organ note pitch data files
2) Munges it (creates a Date Time column for the time stamps), establishes column contents as floats
3) Outputs a new dataframe with mean pitch values, grouped by area of the chapel for comparison with same-location environmental data.
Here I pursue data analysis route 1 (as mentionted in my notebook.md file), which involves comparing one pitch dataframe with one dataframe of environmental characteristics taken at one sensor location. Both dataframes are compared by the time of data recorded.
End of explanation
#I import a pitch data file
#comment by nick changed the path you upload that data from making in compatible with clone copies of your project
pitch=pd.read_table('../Data/pitches.csv', sep=',')
#assigning columns names
#pitch.columns=[['date_time','section','note','freq1','freq2','freq3', 'freq4', 'freq5', 'freq6', 'freq7', 'freq8', 'freq9']]
#I display my dataframe
pitch
output = pitch['freq7'].dtype
output
#Test to see if data is a float
def test_data_type(data):
    '''Check to see if a column contains only floats'''
    obs = pitch['freq7'].dtype #I pass the dtype checking function through my test function
    #print(obs)
    exp = 'float64'
    assert obs == 'float64', 'Data is not a float'
    return
test_data_type(pitch['div'])
#Tell python that my date_time column has a "datetime" values, so it won't read as a string or object
pitch['time']= pd.to_datetime(pitch['time'])
#print the new table and the type of data to check that all columns are in line with the column names
print(pitch)
#Check the type of data in each column. This shows there are integers and floats, and datetime. This is good for analysing.
pitch.dtypes
Explanation: Uploaded data into Python¶
First I upload my data sets. I am working with two: one for pitch measurements and another for environmental characteristics (CO2, temperature (deg C), and relative humidity (RH) (%) measurements). My data comes from environmental sensing logger devices in the "Choir Division" section of the organ consul.
End of explanation
#Calculate MEDIAN of pitch values for each time stamp
#pitch['median_freq'] = [[1,2,3,4,5,] axis=0]
#pitch['median_freq'] = np.median(pitch[3,9], axis=1, 'freq1' 'freq2' 'freq3', 'freq4', 'freq5', 'freq6', 'freq7', 'freq8', 'freq9')
#median_freq = pd.pitches(index=median_freq)
#pitch['median_freq'] = Series(np.random.randn(sLength), index=df1.index)
#pitch['median_freq'] = np.median(pitch[['freq1','freq2','freq3', 'freq4', 'freq5', 'freq6', 'freq7', 'freq8', 'freq9']], axis=1)
#Calculate standard mean of frequency values, add another column to dataframe
pitch['mean_freq'] = np.mean(pitch[['freq1','freq2','freq3', 'freq4', 'freq5', 'freq6', 'freq7', 'freq8', 'freq9']], axis=1)
#Calculate the standard deviation for the mean value of all frequency measurements
pitch['stdev_freq'] = np.std(pitch['mean_freq'])
#Now my data frame has me dian and standard deviation for frequency
pitch
Explanation: Next
1. Find the average pitch value for each date_time, plus standard error/deviation
2. Select out the pitch data for one division at a time. Make an argument
3. Append other pitch files
I have pitch and I have CO2. I want to make a continuous chart of CO2 over time with expected pitch, then plot measured pitch points over that to see if changes in CO2 affect how close the predicted to measured pitch values are.  
How do I generalize the column labels so I can use this script for a file with different number of freq measurements?
End of explanation
#Group by section to compare to environmental measurements from the choir division
#selecting pitch values for the choir division, which is closest to the CO2 sensor
organized_pitch = pitch.groupby(['div']).get_group('choir')
# "organized_pitch" is only a set of pointers to the "pitch" dataframe
organized_pitch
#Save this data frame as a file which can be called into the plotting script
organized_pitch.to_csv('pitch.csv', sep=',') #columns='time', 'div', 'note', 'freq1', 'freq2')
Explanation: These data points can be plotted on top of a calculated pitch line
End of explanation
def make_plot(data):
    plt.figure(figsize=(8,5))
    fig = plt.plot(organized_pitch['time'], organized_pitch['mean_freq'], color = 'navy')
    plt.title('Pitch of C5 Pipe Organ Note')
    plt.ylabel('Sound Frequency (Hz)')
    plt.xlabel('Time of Sample Taken (Apr. 13, 16 and 17, 2010)')
    plt.show()
    return(fig)
make_plot(organized_pitch)
#We can see that pitch changes from ~ 523.9-524.7 Hz
Explanation: I now have an input (raw file) and output (section-selected measured pitch dataframe). This output can be called into my next script, the "env_data.py" file, for comparision between measured and calculated pitch (calculated pitch is calculated from environmental data).
Visualize pitch
Here I make a plot of changed in frequency of the C5 note over time to see if pitch is changing at all, irespective of other environmental variables. (the C note one octave above middle C).
End of explanation
<END_TASK>