Help on built-infunction randn:
randn(...) methodof mtrand.RandomState instance
randn(d0, d1, ..., dn)
Return a sample (or samples) from the "standard normal" distribution.
If positive, int_like orint-convertible arguments are provided,
`randn` generates an arrayof shape ``(d0, d1, ..., dn)``, filled
with random floats sampled from a univariate "normal" (Gaussian)
distribution of mean 0and variance 1 (if anyof the :math:`d_i` are
floats, they arefirst converted to integers by truncation). A single
float randomly sampled from the distribution is returned if no
argument is provided.
This is a convenience function. If you want an interface that takes a
tuple as the first argument, use `numpy.random.standard_normal` instead.
Parameters
----------
d0, d1, ..., dn : int, optional
The dimensions of the returned array, should be all positive.
If no argument is given a single Python floatis returned.
Returns-------
Z : ndarray orfloat
A ``(d0, d1, ..., dn)``-shaped arrayof floating-point samples from
the standard normal distribution, or a single such float if
no parameters were supplied.
See Also
--------
random.standard_normal : Similar, but takes a tuple as its argument.
Notes
-----For random samples from :math:`N(\mu, \sigma^2)`, use:
``sigma * np.random.randn(...) + mu``
Examples
-------->>> np.random.randn()
2.1923875335537315 #random
Two-by-four arrayof samples from N(3, 6.25):
>>>2.5* np.random.randn(2, 4) +3array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], #random
[ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) #random
The map() method on a Series accepts a function or dict-like object containing a mapping.Using map() is a convenient way to perform element-wise transformations and other data cleaning related operations.
data.replace(-999,np.nan) # Replcace one value with one value
01.01NaN22.03NaN4 -1000.053.0dtype:float64
data.replace([-999,-1000],np.nan) # Replace multi-values with one value
01.01NaN22.03NaN4NaN53.0dtype:float64
data.replace([-999,-1000],[np.nan,0])# Replace multi-values with multi-values
01.01NaN22.03NaN40.053.0dtype:float64
data.replace({-999:np.nan,0-1000:0}) # dict can also be passed into replace method
01.01NaN22.03NaN40.053.0dtype:float64
data1=pd.Series(['A','B','c',12])
help(data1.str.replace)
Help onmethod replace inmodule pandas.core.strings:
replace(pat, repl, n=-1, case=True, flags=0) methodof pandas.core.strings.StringMethods instance
Replace occurrences ofpattern/regex in the Series/Index withsome other string. Equivalent to :meth:`str.replace` or
:func:`re.sub`.
Parameters
----------
pat : string
Character sequence or regular expression
repl : string
Replacement sequence
n : int, default-1 (all)
Number of replacements to make fromstartcase : boolean, defaultTrue
If True, casesensitive
flags : int, default0 (no flags)
re module flags, e.g. re.IGNORECASE
Returns-------
replaced : Series/Index of objects
Help onfunction cut inmodule pandas.tools.tile:
cut(x, bins, right=True, labels=None, retbins=False, precision=3, include_lowest=False)
Return indices of half-open bins to which eachvalueof `x` belongs.
Parameters
----------
x : array-like
Input arrayto be binned. It has to be 1-dimensional.
bins : intor sequence of scalars
If `bins` is an int, it defines the number of equal-width bins in the
rangeof `x`. However, in this case, the rangeof `x` is extended
by.1%oneach side to include the min or max valuesof `x`. If
`bins` is a sequence it defines the bin edges allowing for
non-uniform bin width. No extension of the rangeof `x` is done in
this case.
right : bool, optional
Indicates whether the bins include the rightmost edge or not. If
right==True (the default), then the bins [1,2,3,4] indicate
(1,2], (2,3], (3,4].
labels : arrayorboolean, defaultNone
Used as labels for the resulting bins. Must be of the same length as
the resulting bins. If False, returnonlyinteger indicators of the
bins.
retbins : bool, optional
Whether toreturn the bins or not. Can be useful if bins is given
as a scalar.
precision : int
The precisionat which to store and display the bins labels
include_lowest : bool
Whether the firstinterval should be left-inclusive or not.
Returns-------out : Categorical or Series orarrayof integers if labels isFalse
The return type (Categorical or Series) depends on the input: a Series
of type category if input is a Series else Categorical. Bins are
represented as categories when categorical data is returned.
bins : ndarray of floats
Returned only if `retbins` is True.
Notes
-----
The `cut` function can be useful for going from a continuous variable to
a categorical variable. For example, `cut` could convert ages togroupsof age ranges.
Any NA values will be NA in the result. Outof bounds values will be NA in
the resulting Categorical object
Examples
-------->>> pd.cut(np.array([.2, 1.4, 2.5, 6.2, 9.7, 2.1]), 3, retbins=True)
([(0.191, 3.367], (0.191, 3.367], (0.191, 3.367], (3.367, 6.533],
(6.533, 9.7], (0.191, 3.367]]
Categories (3, object): [(0.191, 3.367] < (3.367, 6.533] < (6.533, 9.7]],
array([ 0.1905 , 3.36666667, 6.53333333, 9.7 ]))
>>> pd.cut(np.array([.2, 1.4, 2.5, 6.2, 9.7, 2.1]), 3,
labels=["good","medium","bad"])
[good, good, good, medium, bad, good]
Categories (3, object): [good < medium < bad]
>>> pd.cut(np.ones(5), 4, labels=False)
array([1, 1, 1, 1, 1], dtype=int64)
Help onfunction value_counts inmodule pandas.core.algorithms:
value_counts(values, sort=True, ascending=False, normalize=False, bins=None, dropna=True)
Compute a histogram of the counts of non-null values.
Parameters
----------values : ndarray (1-d)
sort : boolean, defaultTrue
Sort byvalues
ascending : boolean, defaultFalse
Sort in ascending ordernormalize: boolean, defaultFalse
If Truethen compute a relative histogram
bins : integer, optional
Rather than count values, group them into half-open bins,
convenience for pd.cut, only works withnumeric data
dropna : boolean, defaultTrue
Don't include counts of NaN
Returns
-------
value_counts : Series
Help on built-infunction bin inmodule builtins:
bin(number, /)
Return the binary representation of an integer.
>>> bin(2796202)
'0b1010101010101010101010'
bin(2)
'0b10'
bins can also be an integer, and in that case, the category will be equal-space.
data=np.random.rand(20)
pd.cut(data,4,precision=2)# precision limits the decimal precision to two digits.
A closely related function,qcut,bins the data based on sample quantiles.Using cut will not usually result in each bin having the same number of data points.
Help on function anyin module pandas.core.frame:
any(self, axis=None, bool_only=None, skipna=None, level=None, **kwargs)
Return whether any element isTrue over requested axis
Parameters
----------
axis : {index (0), columns (1)}
skipna : boolean, default True
Exclude NA/null values. If an entire row/column is NA, the result
will be NA
level : intor level name, default None
If the axis is a MultiIndex (hierarchical), count along a
particular level, collapsing into a Series
bool_only : boolean, default None
Include only boolean columns. If None, will attempt to use everything,
then use only boolean data. Not implemented for Series.
Returns
-------
any : Series or DataFrame (if level specified)
(abs(data)>3) ==(np.abs(data)>3)
0
1
2
3
0
True
True
True
True
1
True
True
True
True
2
True
True
True
True
3
True
True
True
True
4
True
True
True
True
5
True
True
True
True
6
True
True
True
True
7
True
True
True
True
8
True
True
True
True
9
True
True
True
True
10
True
True
True
True
11
True
True
True
True
12
True
True
True
True
13
True
True
True
True
14
True
True
True
True
15
True
True
True
True
16
True
True
True
True
17
True
True
True
True
18
True
True
True
True
19
True
True
True
True
20
True
True
True
True
21
True
True
True
True
22
True
True
True
True
23
True
True
True
True
24
True
True
True
True
25
True
True
True
True
26
True
True
True
True
27
True
True
True
True
28
True
True
True
True
29
True
True
True
True
...
...
...
...
...
970
True
True
True
True
971
True
True
True
True
972
True
True
True
True
973
True
True
True
True
974
True
True
True
True
975
True
True
True
True
976
True
True
True
True
977
True
True
True
True
978
True
True
True
True
979
True
True
True
True
980
True
True
True
True
981
True
True
True
True
982
True
True
True
True
983
True
True
True
True
984
True
True
True
True
985
True
True
True
True
986
True
True
True
True
987
True
True
True
True
988
True
True
True
True
989
True
True
True
True
990
True
True
True
True
991
True
True
True
True
992
True
True
True
True
993
True
True
True
True
994
True
True
True
True
995
True
True
True
True
996
True
True
True
True
997
True
True
True
True
998
True
True
True
True
999
True
True
True
True
1000 rows × 4 columns
data[(np.abs(data)>3).any(1)]
0
1
2
3
59
-3.400618
0.342563
0.649758
-2.629268
274
1.264869
-3.427137
0.991494
-0.906788
322
2.714233
-1.239436
3.059163
0.318054
431
-0.376058
-0.713530
-3.089013
-0.791221
460
0.411801
-0.323974
0.301139
-3.051362
465
0.054043
-1.046532
2.054820
-4.375632
587
0.857067
-3.162763
0.137409
-1.327873
648
-0.323629
0.325867
-4.309211
-0.477572
653
0.171840
0.148702
3.784272
0.269508
678
0.303109
3.171119
0.854269
0.489537
834
1.651314
1.303992
3.007481
0.494971
841
3.408137
0.869413
-0.111245
1.306775
960
-0.302520
-3.118445
2.116509
0.003669
np.sign([0,0.3,-0.3,20,-90])
array([ 0., 1., -1., 1., -1.])
data[np.abs(data)>3]=np.sign(data)*3
np.sign(data)*3
0
1
2
3
0
-3.0
-3.0
-3.0
3.0
1
-3.0
3.0
3.0
-3.0
2
3.0
3.0
3.0
3.0
3
-3.0
-3.0
-3.0
-3.0
4
3.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0
-3.0
-3.0
-3.0
996
3.0
-3.0
3.0
-3.0
997
-3.0
-3.0
-3.0
-3.0
998
3.0
3.0
-3.0
-3.0
999
3.0
3.0
3.0
-3.0
1000 rows × 4 columns
data
0
1
2
3
0
-0.564062
-0.887969
-0.854782
0.107613
1
-1.364165
1.337851
1.671698
-0.814129
2
0.765877
1.916774
0.441002
2.128419
3
-0.581957
-1.024641
-1.983024
-2.757392
4
0.778034
-1.375845
0.044277
-1.037062
5
-0.796683
-0.540663
-0.120198
0.003503
6
-0.708554
-0.105414
1.037527
0.826310
7
1.233856
1.217529
1.097430
0.842746
8
-0.201433
0.249823
-1.620147
0.436595
9
1.328493
-0.396323
1.927629
1.615656
10
-0.560207
0.252996
-0.151543
-0.667813
11
-1.729057
1.144087
1.087689
0.520086
12
0.704758
1.707940
0.720834
0.447245
13
1.024834
-0.217376
1.340304
0.176801
14
0.075745
1.430761
0.193627
0.191701
15
0.536566
0.047559
1.715175
-1.115074
16
2.803965
-0.465377
1.127140
1.417856
17
0.677525
-1.091631
-0.572231
0.241533
18
-1.172228
1.049830
0.266288
0.836902
19
0.930699
0.379891
1.637741
-1.770379
20
-0.749769
0.711326
1.591292
1.099071
21
1.550585
1.276488
-0.214484
0.195340
22
-0.289236
1.882439
-0.275263
-0.247316
23
0.688167
0.357913
-1.675828
-0.305840
24
1.255532
-1.802804
0.889900
0.864982
25
-1.391447
-0.291022
-0.190022
0.540653
26
0.435101
2.444416
-1.235937
-0.428450
27
0.165456
-1.091942
-1.560662
-0.739435
28
1.469728
-0.123806
-2.071746
2.574603
29
1.287949
1.278130
-0.825906
-1.852465
...
...
...
...
...
970
-0.379102
-0.778606
2.213794
-0.062573
971
-1.108557
0.723650
-2.436704
-0.068733
972
-0.518995
0.455508
-0.217321
1.363977
973
0.444636
1.625221
0.222103
1.236397
974
0.699354
-2.076747
-0.454499
0.383902
975
-1.759718
0.717117
-0.077413
1.698893
976
-1.230778
0.222673
0.151731
0.174875
977
-0.575290
-0.316810
0.380077
-0.048428
978
1.906133
-0.861802
-0.026937
-2.865641
979
-0.134489
0.607949
-0.821089
0.831827
980
-0.058894
-0.707492
-0.273980
0.129724
981
2.288519
0.149683
0.580679
-0.055218
982
-0.280748
0.861358
-0.254339
-0.596723
983
-1.322965
0.323534
-0.585862
-1.316894
984
0.793711
0.165646
-0.212855
-1.752453
985
0.310908
0.758156
-0.040923
0.538293
986
-0.589173
-1.688947
-0.501485
0.019880
987
-0.111807
1.007026
-0.853133
-0.249211
988
0.601993
0.690953
-1.168277
-0.516737
989
1.319895
-0.046141
-0.680194
1.443361
990
1.839785
-0.480675
0.056481
-0.097993
991
2.590916
-0.367057
1.110105
0.130826
992
-0.108846
1.717209
-0.580895
-0.985869
993
-1.152810
0.390732
-0.104866
1.553947
994
1.721177
-0.088994
-0.565308
-1.602808
995
0.922409
-0.027923
-1.258001
-1.933848
996
0.647699
-0.089378
1.455509
-0.598519
997
-1.590236
-0.544202
-0.764923
-0.329425
998
0.969542
0.106538
-0.188919
-1.474017
999
0.235337
0.232514
0.113181
-1.403455
1000 rows × 4 columns
np.sign(data).head(10) # return the first 10 rows.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix