In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what pandas computing tools are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Statistical function growth rate pct_change
Sequences (Series), data frames (DataFrame), and Panel (panels) all have pct_change methods to calculate the growth rate (you need to use fill_method to fill in the null values first)
Series.pct_change (periods=1, fill_method='pad', limit=None, freq=None, * * kwargs)
Periods parameter control step
In [1]: ser = pd.Series (np.random.randn (8)) In [2]: ser.pct_change () Out [2]: 0 NaN1-1.6029762 4.3349383-0.2474564-2.0673455-1.1429036-1.6882147-9.759729dtype: float64 covariance Covariance
Sequence Series objects have cov methods to calculate covariances
Series.cov (other, min_periods=None)
In [5]: S1 = pd.Series (np.random.randn (1000)) In [6]: S2 = pd.Series (np.random.randn (1000)) In [7]: s1.cov (S2) Out [7]: 0.00068010881743108746
The cov method of the data frame DataFrame object
DataFrame.cov (min_periods=None)
In [8]: frame = pd.DataFrame (np.random.randn (1000, 5), columns= ['averse,' baked, 'crested,' d' In [9]: frame.cov () Out [9]: a b c d ea 1.000882-0.003177-0.002698-0.006889 0.031912b-0.003177 1.024721 0.000191 0.009212 0.000857c-0.002698 0.000191 0.950735-0.031743-0.005087d-0.006889 0.009212-0.031743 1.002983-0.047952e 0.031912 0.000857-0.005087-0.047952 1.042487 correlation coefficient Correlation
There are three methods to calculate the correlation coefficient.
Method nameDescriptionpearson? (default) Standard correlation coefficientkendallKendall Tau correlation coefficientspearmanSpearman rank correlation coefficient
Series.corr (other, method='pearson', min_periods=None)
DataFrame.corr (method='pearson', min_periods=1)
In [15]: frame = pd.DataFrame (np.random.randn (1000, 5), columns= ['averse,' baked, 'crested,' d' ) In [19]: frame.corr () Out [19]: a b c d ea 1.000000 0.013479-0.049269-0.042239-0.028525b 0.013479 1.000000-0.020433-0.011139 0.005654c-0.049269-0.020433 1.000000 0.018587-0.054269d-0.042239-0.011139 0.018587 1.000000-0.017060e-0 .028525 0.005654-0.054269-0.017060 1.000000
DataFrame.corrwith (other, axis=0, drop=False)
Data ranking
Series.rank (axis=0, method='average', numeric_only=None, na_option='keep', ascending=True, pct=False)
In [31]: s = pd.Series (np.random.np.random.randn (5), index=list ('abcde')) In [32]: s [' d'] = s ['b'] # so there's a tieIn [33]: s.rank () Out [33]: a 5.0b 2.5c 1.0d 2.5e 4.0dtype: float64
DataFrame.rank (axis=0, method='average', numeric_only=None, na_option='keep', ascending=True, pct=False)
Axis=0 sorts by row, and axis=1 sorts by column
Ascending=True is ascending order, False is descending order
In [34]: df = pd.DataFrame (np.random.np.random.randn (10 6) In [35]: df [4] = df [2] [: 5] # some tiesIn [36]: dfOut [36]: 01 23 4 50-0.904948-1.163537-1.457187 0.135463-1.457187 0.2946501-0.976288-0.244652-0.748406-0.748406-0.8008092 0.401965 1.460840 1.256057 1.308127 1.256057 0.8760043 0.205954 0.369552-0.669304 0.038378-0 . 669304 1.1402964-0.477586-0.730705-1.129149-0.601463-1.129149-0.2111965-1.092970-0.689246 0.908114 0.204848 NaN 0.4633476 0.376892 0.959292 0.095572-0.593740 NaN-0.0691807-1.002601 1.957794-0.120708 0.094214 NaN-1.4674228-0.547231 0.664402-0.519424-0.073254 NaN-1.2635449-0.250277 -0.237428-1.056443 0.419477 NaN 1.375064In [37]: df.rank (1) Out [37]: 01 23 4 50 3.0 1.5 5.0 1.5 6.01 2.0 6.0 4.5 4.5 3.02 1.0 6.0 3.5 5.0 2.03 4.0 1.5 3.0 1.5 6.04 5.0 3.0. 5 4.0 1.5 6.05 1.0 2.0 5.0 3.0 NaN 4.06 4.0 5.0 3.0 1.0 NaN 2.07 2.0 5.0 3.0 4.0 NaN 1.08 2.0 5.0 3.0 4.0 NaN 1.09 2.0 1.0 4.0 NaN 5.0 window functions introduction to rolling
Series.rolling (window, min_periods=None, freq=None, center=False, win_type=None, on=None, axis=0)
Window: the size of the moving window
Min_periods:??
Center: whether to set the label in the middle. Default is False.
Win type=??
In [38]: s = pd.Series (np.random.randn (1000), index=pd.date_range ('1max 2000 pounds, periods=1000)) r = s.rolling (window=60) In [42]: rOut [42]: Rolling [window=60,center=False Axis=0] In [43]: r.mean () Out [43]: 2000-01-01 NaN2000-01-02 NaN2000-01-03 NaN2000-01-04 NaN2000-01-05 NaN2000-01-06 NaN2000-01-07 NaN... 2002-09-20-62.6941352002-09-21-62.8121902002 09-22-62.9149712002-09-23-63.0618672002-09-24-63.2138762002-09-25-63.3750742002-09-26-63.539734Freq: d, dtype: float64In [44]: s.plot (style='k--') Out [44]: In [45]: r.mean (). Plot (style='k') Out [45]:
The summary in the data box will be applied to each column
DataFrame.rolling (window, min_periods=None, freq=None, center=False, win_type=None, on=None, axis=0)
In [46]: df = pd.DataFrame (np.random.randn (1000, 4),....: index=pd.date_range ('1racer 2000), periods=1000),....: columns= [' A','B','C','D'])....: In [47]: df = df.cumsum () In [48]: df.rolling (window=60). Sum (). Plot (subplots=True)
Summary of calculation methods MethodDescriptioncount () Number of non-null observationssum () Sum of valuesmean () Mean of valuesmedian () Arithmetic median of valuesmin () Maximumstd () Bessel-corrected sample standard deviationvar () Unbiased varianceskew () Sample skewness (3rd moment) kurt () Sample kurtosis (4th moment) quantile () Sample quantile (value at%) apply () Generic applycov () Unbiased covariance (binary) corr () Correlation (binary)
The apply () method can be applied to a scrolling window. The parameter function of apply () must mean to produce a value, assuming that we need to calculate the mean absolute deviation:
In [49]: mad = lambda x: np.fabs (x-x.mean ()) .mean () In [50]: s.rolling (window=60) .apply (mad) .plot (style='k')
Use aggregate function (Aggregation) expand window (Expanding Windows) exponentially weighted window (Exponentially Weighted Windows) these are all the contents of this article "what are the pandas Computing tools?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.