Shanghai Jiao Tong University Senior Mei Sun Peking University Freshman Changqiang You Shanghai Jiao Tong University Freshman Gaopeng Yang sectionĬonstruct a multilevel index first df.set_index() Uniform sampling with return can be written as follows: df_sample.sample(3,replace =True,weights=np.ones(5)) #The same weight means uniform samplingĪs the name suggests, multi-level index means that columns and rows are no longer a single attribute, but multiple attributes. The sampling function resample, whose main parameter is replace, indicates whether it has been put back or not, and weights, which represents the sampling probability of each sample, for example:.When using Boolean list, iloc cannot pass in Series, but must pass in values of sequence. iloc slicing is the slicing of positions and does not contain the ending endpoint. When using loc slicing, the index value is sliced, and the slice contains two endpoints. Summarize the differences between iloc and loc Using loc, you can directly pass in Series: df.locĪnd loc with or without values can be as follows: df.loc When using a Boolean list, you should pay special attention to that you cannot pass in Series, but you must pass in the values of the sequence, as follows: df.iloc Ilco is used to slice the integer index df.ilocįrom this we can see that the slice is a slice of the position and does not contain the end point. Iloc and loc are basically the same, but they are indexed for location. When using loc slicing, the index value is sliced, and the slice contains the endpoint. Without using any function, the direct slicing is based on the position, but when using the loc slice, the results are as follows: df.loc For integer index, when slicing directly, the result is as follows: dfĥ Shanghai Jiao Tong University Freshman Gaopeng YangĤ Peking University Freshman Changqiang Youģ Shanghai Jiao Tong University Senior Mei SunĢ Fudan University Sophomore Xiaojuan Sun Loc has two inputs, the first is a row and the second is a column. The fourth element is retrieved, but the index of a row is the same as before: s When slicing an integer index, the value of position is taken out, for example: s = pd.Series(,index=(1,3,4,2)) To slice a duplicate index, such as a, sort it first and then slice it s.sort_index() Because all indexes have unique 'b' and 'c', no error will be reported. Used to retrieve the intermediate value of two indexes and return two endpoints that will contain slices, as follows: s = pd.Series(, index=)Īt this time, the endpoints b and c are also returned.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |