(1) Pandas. Series.value_counts: Returns the number of unique values contained in the object,
Series. value_counts (Normalize=false, Sort=true, Ascending=false, Bins=none,dropna=true)
Parameters: |
Normalize : Boolean, default False Returns the relative frequency of counts if true Sort : Boolean, default True To sort a value Ascending : Boolean, default False Default to counts descending order Bins : integer, optional Not the number of returns, but the half-open group interval, easy to use pd.cut, only useful for numerical data Dropna : Boolean, default True The default does not contain the number of Nan |
return value: |
counts : Series |
Example:
Output Result:
(2) S.values_counts (). Reset_index (), adding rows to the index
(3) Df_today = Df[df.insertday = = Dt1] Remove the row in the data frame insertday corresponding to the value DT1.
(4) X.shape can be applied to a variety of storage results, viewing the dimensions of each dimension, but not to a single value.
(5) From scipy.stats import Ks_2samp is a chip python built-in function that calculates two data samples distribution KS statistic, function ks_2samp (S1,S2) = (ks,p), return KS value, and double tail test p-value.
(6) Isinstance (value, float), judging the object data type, returns True Orfalse
(7) Round (x,n), returns the rounding value of the floating-point number x.
(8) Exception handling: Avoid errors in the middle of the program to stop running, but in another way, or the exception is indicated.
Try:
<...............> # could get an exception to the statement
except<.......>: # What kind of exception is locked
<...............> # How to handle exceptions
(9) If __name__ = = ' __main__ ':
The module is an object, and all modules have a built-in property of __name__. The value of the __name__ of a module depends on how you apply the module. If you import a module, the value of the module __name__ is usually the module file name, without the path or file extension. But you can also run the module directly like a standard program, in which case the __name__ value will be a special default "__main__".
#Test. py
Classtest:
def __init (self):p
def f (self):p rint ' Hello, world! '
if__name__ = = ' __main__ ':
Test (). F ()
#End
Help (function) can show how to use the function
(one) Zip (seq1 [, SEQ2 [...]]), [(Seq1[0], seq2[0] ...), (...) : Returns a list with elements that are tuples and corresponding elements in each list.
Output Result:
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
(one) dict ()
Output:
Note: with dict () , the order is scrambled, because the dictionary is stored in a way that is not sequential, so it is faster, and the dictionary is keyed to the value, and there is no effect.
Python Learning 2016.4.1