<jupyter_start><jupyter_text>0. Creating Ndarray   numpy.array(object, dtype = None, copy = True, order = None, subok = False, ndmin = 0) Parameters:	object : array_like. an array-like is any Python object that np.array can convert to an ndarray. From the source code, we can infer that the  array_like object can be:1.a NumPy array, or2.a NumPy scalar, or3.a Python scalar, or4.any object which supports the PEP 3118 buffer interface, or5.any object that supports the __array_struct__ or __array_interface__ interface, or6.any object that supplies the __array__ function, or7.any object that can be treated as a list of lists Sum up, An array, any object exposing the array interface, an object whose __array__ method returns an array, or any (nested) sequence.dtype : data-type, optional. The desired data-type for the array. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence. This argument can only be used to ‘upcast’ the array. For downcasting, use the .astype(t) method.copy : bool, optional. If true (default), then the object is copied. Otherwise, a copy will only be made if __array__ returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (dtype, order, etc.).order : {‘K’, ‘A’, ‘C’, ‘F’}, optional. Specify the memory layout of the array. If object is not an array, the newly created array will be in C order (row major) unless ‘F’ is specified, in which case it will be in Fortran order (column major). If object is an array the following holds.order	   no copy	   copy=True‘K’	       unchanged	F & C order preserved, otherwise most similar order‘A’	      unchanged	    F order if input is F and not C, otherwise C order‘C’	      C order	    C order‘F’	      F order	    F orderorder	no copy	copy=True‘K’	unchanged	F & C order preserved, otherwise most similar order‘A’	unchanged	F order if input is F and not C, otherwise C order‘C’	C order	C order‘F’	F order	F orderWhen copy=False and a copy is made for other reasons, the result is the same as if copy=True, with some exceptions for A, see the Notes section. The default order is ‘K’.subok : bool, optional. If True, then sub-classes will be passed-through, otherwise the returned array will be forced to be a base-class array (default).ndmin : int, optional. Specifies the minimum number of dimensions that the resulting array should have. Ones will be pre-pended to the shape as needed to meet this requirement.Returns:	out : ndarray. An array object satisfying the specified requirements. When order is ‘A’ and object is an array in neither ‘C’ nor ‘F’ order, and a copy is forced by a change in dtype, then the order of the result is not necessarily ‘C’ as expected. This is likely a bug.<jupyter_code>np.array([[1,2,3],[2,3,4]],dtype=int,copy=True, order='C',subok=False,ndmin=3)
 np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')])
np.array(np.mat('1 2; 3 4'))<jupyter_output><empty_output><jupyter_text>Check internal memory layouthttps://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.ndarray.html   1. Creating Series    class pandas.Series(data=None, index=None, dtype=None, name=None, copy=False, fastpath=False)[source]One-dimensional ndarray with axis labels (including time series).Labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Statistical methods from ndarray have been overridden to automatically exclude missing data (currently represented as NaN).Operations between Series (+, -, /, , *) align values based on their associated index values– they need not be the same length. The result index will be the sorted union of the two indexes.  Parameters:	 data : array-like, dict, or scalar value Contains data stored in Seriesindex : array-like or Index (1d)  Values must be hashable and have the same length as data.  Non-unique index values are allowed. Will default to RangeIndex(len(data)) if not provided. If both a dict and index sequence are used, the index will override the keys found in the dict.If data is an ndarray, index must be the same length as data. If no index is passed, one will be created having values [0, ..., len(data) - 1].dtype : numpy.dtype or None If None, dtype will be inferredcopy : boolean, default False. Copy input dataLabels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Statistical methods from ndarray have been overridden to automatically exclude missing data (currently represented as NaN).Operations between Series (+, -, /, , *) align values based on their associated index values– they need not be the same length. The result index will be the sorted union of the two indexes.<jupyter_code>pd.Series(3)
pd.Series(np.random.randn(5),index=['a','b','c','d','e'])
s.index
pd.Series({'a':1.,'b':2,'c':3})<jupyter_output><empty_output><jupyter_text>Note NaN (not a number) is the standard missing data marker used in pandas<jupyter_code>pd.Series(5., index=['a', 'b', 'c', 'd', 'e'])<jupyter_output><empty_output><jupyter_text>Series is ndarray-like. Series acts very similarly to a ndarray, and is a valid argument to most NumPy functions. However, things like slicing also slice the index.  2. Creating DataFrame  pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)  Two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. Can be thought of as a dict-like container for Series objects. The primary pandas data structure Parameters:	data : numpy ndarray (structured or homogeneous), dict, or DataFrameDict can contain Series, arrays, constants, or list-like objectsindex : Index or array-likeIndex to use for resulting frame. Will default to np.arange(n) if no indexing information part of input data and no index providedcolumns : Index or array-likeColumn labels to use for resulting frame. Will default to np.arange(n) if no column labels are provideddtype : dtype, default NoneData type to force. Only a single dtype is allowed. If None, infercopy : boolean, default FalseCopy data from inputs. Only affects DataFrame / 2d ndarray input  1. The most straightforward way, is by creating it from a NumPy array.<jupyter_code>a=pd.DataFrame(np.array([[10, 11], [20, 21]]))
a
b=pd.DataFrame(a)
b<jupyter_output><empty_output><jupyter_text>Each row of the array forms a row in the DataFrame object.  2. A DataFrame can also be initialized by passing a list of Series objects.<jupyter_code>df1 = pd.DataFrame([pd.Series(np.arange(10, 15)),
                       pd.Series(np.arange(15, 20))])
df1<jupyter_output><empty_output><jupyter_text>The dimensions of a DataFrame object can be determined using its .shape property.<jupyter_code>df = pd.DataFrame(np.array([[10, 11], [20, 21]]),
                  columns=['a', 'b'],
                 index=['r1', 'r2'])
df<jupyter_output><empty_output><jupyter_text>The names of the columns of a DataFrame can be accessed with its .columns property:  3. A DataFrame object can also be created by passing a dictionary containing one or more Series objects, where the dictionary keys contain the column names and each series is one column of data:<jupyter_code>s1 = pd.Series(np.arange(1, 6, 1))
s2 = pd.Series(np.arange(6, 11, 1))
df3=pd.DataFrame({'c1': s1, 'c2': s2})
df3<jupyter_output><empty_output><jupyter_text>When the DataFrame is created, each series in the dictionary is aligned with each other by the index label, as it is added to the DataFrame object.<jupyter_code>df=pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
df<jupyter_output><empty_output><jupyter_text>Selecting columns of a DataFrameSelecting the data in specifc columns of a DataFrame is performed by using the [] operator. This can be passed either as a single object, or a list of objects.<jupyter_code>df
df['col1']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0863362440044275, 'fraction_numerical': 0.012175624154470545, 'mean_word_length': 4.734837799717913, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 37, 'https://': 1, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '445638', 'license': 'Apache-2.0', 'n_tokens_mistral': 2342, 'n_tokens_neox': 2276, 'n_words': 1098, 'path': 'create_ndArray.ipynb', 'repo_name': 'yangzhou95/notes', 'size': '8131'}