Package: sharks
Data Analysis Library SharksThis repository contains a detailed note of a new data analysis library Sharks.ObjectivesSharks :Has A DataFrame class with data stored in numpy arraysCan Select subsets of data with the brackets operatorCan Use special methods defined in the Python data modelHave a nicely formatted display of the DataFrame in the notebookCan Implement aggregation methods - sum, min, max, mean, median, etc...Can Implement non-aggregation methods such as isna, unique, rename, dropCan Group by one or two columnsHave methods specific to string columnsCan Read in data from a comma-separated value fileFunctionalities of Sharks1. DataFrame constructor input typesOur DataFrame class is constructed with a single parameter.Specifically, input types must qualify the following:Sharks will raise aTypeErrorifdatais not a dictionarySharks will raise aTypeErrorif the keys ofdataare not stringsSharks will raise aTypeErrorif the values ofdataare not numpy arraysSharks will raise aValueErrorif the values ofdataare not 1-dimensional2. Array lengthsWe are now guaranteed thatdatais a dictionary of strings mapped to one-dimensional arrays. Each column of data in our DataFrame must have the same number of elements.3. Convert unicode arrays to objectWhenever you create a numpy array of Python strings, it will default the data type of that array to unicode. Take a look at the following simple numpy array created from strings. Its data type, found in thedtypeattribute is shown to be 'U' plus the length of the longest string.>>>a=np.array(['cat','dog','snake'])>>>a.dtypedtype('<U5')Unicode arrays are more difficult to manipulate and don't have the flexibility that we desire. So, if our user passes us a Unicode array, we will convert it to a data type called 'object'. This is a flexible type and will help us later when creating methods just for string columns. Technically, this data type allows any Python objects within the array.4. Find the number of rows in the DataFrame with thelenfunctionThe number of rows are returned when passing a pandas DataFrame to the builtinlenfunction.5. Return columns as a listdf.columnswill return a list of the column names.6. Set new column nameswe can assign all new columns to our DataFrame by setting the columns property equal to a list. A example below shows how you would set new columns for a 3-column DataFrame.df.columns=['state','age','fruit']Also Sharks will raise errors if the data that is inserted is invalid.Sharks will Raise aTypeErrorif the object used to set new columns is not a listSharks will Raise aValueErrorif the number of column names in the list does not match the current DataFrameSharks will Raise aTypeErrorif any of the columns are not stringsSharks will Raise aValueErrorif any of the column names are duplicated in the list7. TheshapepropertyTheshapeproperty will return a two-item tuple of the number of rows and columns.8. Visual HTML representation in the notebook with the_repr_html_methodThe_repr_html_method is made available to developers by iPython so that your objects can have nicely formatted HTML displays within Jupyter Notebooks. Read more on this method [here in the iPython documentation][12] along with other similar methods for different representations.9. Thevaluespropertyvaluesis a property that returns a single array of all the columns of data.10. ThedtypespropertyThedtypesproperty will return a two-column DataFrame with the column names in the first column and their data type as a string in the other. Use 'Column Name' and 'Data Type' as column names.11. Select a single column with the bracketsIn Sharks, you can select a single column withdf['colname'].12. Select multiple columns with a listSharks will also be able to select multiple columns if given a list within the brackets. For example,df[['colname1', 'colname2']]will return a two column DataFrame.13. Boolean Selection with a DataFrameIn Sharks, you can filter for specific rows of a DataFrame by passing in a boolean Series/array to the brackets. For instance, the following will select only the rows such thatais greater than 10.>>>s=df['a']>10>>>df[s]14. Check for simultaneous selection of rows and columns15. Select a single cell of dataSharks can select a single cell of data withdf[rs, cs]. We will assumersis an integer andcsis either an integer or a string.16. Simultaneously select rows as booleans, lists, or slicesSharks can select rows and columns simultaneously withdf[rs, cs]. We will allowrsto be either a single-column boolean DataFrame, a list of integers, or a slice.17. Simultaneous selection with multiple columns as a list18.  Simultaneous selection with column slicesSharks will allow  columns to be sliced with either strings or integers. The following selections will be acceptable.19. Tab Completion for column names20. Create a new column or overwrite an old column21.headandtailmethodsTheheadandtailmethods each accept a single integer parameternwhich is defaulted to 5.22. Generic aggregation methodsSharks can implement several methods that perform an aggregation. These methods all return a single value for each column. The following aggregation methods are defined.minmaxmeanmediansumvarstdallanyargmax - index of the maximumargmin - index of the minimum23.isnamethodTheisnamethod will return a DataFrame the same shape as the original but with boolean values for every single value. Each value will be tested whether it is missing or not. Usenp.isnanexcept in the case for strings which you can use a vectorized equality expression toNone.24.countmethodThecountmethod returns a single-row DataFrame with the number of non-missing values for each column. You will want to use the result ofisna.25.uniquemethodThis method will return the unique values for each column in the DataFrame. Specifically, it will return a list of one-column DataFrames of unique values in each column. If there is a single column, just return the DataFrame.26.nuniquemethodReturn a single-row DataFrame with the number of unique values for each column.27.value_countsmethod28. Normalize options forvalue_counts29.renamemethodTherenamemethod renames one or more column names. Accept a dictionary of old column names mapped to new column names. Return a DataFrame. Raise aTypeErrorifcolumnsis not a dictionary.30.dropmethodAccept a single string or a list of column names as strings. Return a DataFrame without those columns. Raise aTypeErrorif a string or list is not provided.31. Non-aggregation methodsThere are several non-aggregation methods that function similarly. All of the following non-aggregation methods return a DataFrame that is the same shape as the origin.abscummincummaxcumsumcliproundcopy32. Arithmetic and Comparison OperatorsAll the common arithmetic and comparison operators will be made available to our DataFrame. For example,df + 5uses the plus operator to add 5 to each element of the DataFrame. Take a look at some of the following examples:df+5df-5df>5df!=55+df5<df33.sort_valuesmethodThis method will sort the rows of the DataFrame by one or more columns. Allow the parameterbyto be either a single column name as a string or a list of column names as strings. The DataFrame will be sorted by this column or columns.34.pivot_tablemethod35. Reading simple CSVsTheread_csvfunction, will read in simple comma-separated value files (CSVs) and return a DataFrame.