()Print(c isA#False (C and a point to memory addresses are different)#copy A, assign a value to C#if it is c=a, then C and a are the same (point to the same address)#Print (c is a) in the word, it prints truec[1,2] = 100Print(a)" "[ [1 2 3] [4 5] [7 8 9]]" "#here we find that C has been modified, so a has also been modified.#C and a have different addresses but share a set of dataD=a.copy ()Print(d isA#falsed[1,3] = 100#There's no change here .Print(a)Read TXT file:Import NumPy # The first para
Original addressThe coding of discrete features is divided into two situations:1, the value of discrete features do not have the meaning of the size, such as Color:[red,blue], then use one-hot encoding2, discrete characteristics of the value of the size of the meaning, such as SIZE:[X,XL,XXL], then use the value of the map {X:1,xl:2,xxl:3}It is convenient to use pandas to one-hot encoding of discrete features
Import
Import NumPy as NP
Import Pandas as PD
DATA=PD. Dataframe (Np.arange (6). Reshape ((3,2)), INDEX=PD. Index ([' A ', ' B ', ' C '],name= ' state '), COLUMNS=PD. Index ([' I ', ' II '],name= ' number ')]
Data
Number I II
State
A 0 1
B 2 3
C 4 5
Result=data.unstack ()
Result
Number State
I a 0
B 2
C 4
II a 1
B 3
C 5
Type (Result) #pandas. Core.series.Ser
1 concat
The Concat function is a method underneath the pandas that allows for a simple fusion of data based on different axes.
Pd.concat (Objs, axis=0, join= ' outer ', Join_axes=none, Ignore_index=false, Keys=none, Levels=none, Names=None,
Verify_integrity=false)1 2 1 2 1 2
Parameter descriptionObjs:series,dataframe or a sequence of panel compositions lsitAxis: Axis that needs to merge links, 0 is row, 1 is columnJoin: Connecting the way i
dateframe Modify column names in Pandas
The data are as follows:
>>>import pandas as PD
>>>a = PD. Dataframe ({' A ': [1,2,3], ' B ': [4,5,6], ' C ': [7,8,9]})
>>> a
a B C
0 1 4 7
1 2 5 8
2 3 6 91 2 3 4 5 6 7 1 2 3 4 5 6-7
method One: Methods of violence
>>>a.columns = [' A ', ' B ', ' C ']
>>>a
a b c
0 1 4 7
1 2 5 8
2 3 6 91 2 3 4 5 6 1 2 3 4 5-6
But the disadvantage is that you
The is very simple to use when data manipulation is done through the Pandas library, and then a brief instance is written to the CSV file:
In [1]: Import pandas as PD in [2]: data = {' Row1 ': [1,2,3, ' Biubiu '], ' row2 ': [3,1,3, ' Kaka ']} in [3]: Data out[3]: {' row1 ': [1, 2, 3, ' Biubiu '], ' row2 ': [3, 1, 3, ' Kaka ']} in [4]: DATA_DF = PD.
Dataframe (data) in [5]: DATA_DF out[5]: row1 row2 0
Abstract: This article is mainly to explain how to sort. There are two kinds of cases, no grouping and sorting within the group. What does that mean. Specifically, I raise a chestnut.
Pay attention to * * *
If you simply want to sort a column without making a serial number, use it directly. Sort_values on it. The following is about how to put the serial number on the phone.
————————————————————————————
We have a dataset as follows:
We want to do two kinds of sorting below. First of all, simple
Hierarchical Indexing)
Create a series. When you input an Index, enter a list consisting of two sub-lists. The first sub-list is the outer index, and the second list is the inner index.
Sample Code:
import pandas as pdimport numpy as npser_obj = pd.Series(np.random.randn(12),index=[ [‘a‘, ‘a‘, ‘a‘, ‘b‘, ‘b‘, ‘b‘, ‘c‘, ‘c‘, ‘c‘, ‘d‘, ‘d‘, ‘d‘], [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] ])print(ser_obj)
Running re
Below for you to share a pandas implementation will repeat the table to weight, and re-converted to a table method, has a good reference value, I hope to be helpful to everyone. Come and see it together.
Dataframe and set are often used when processing data in Python.
Train=pd.read_csv (' xxx.csv ') #读取文件 train=train[' item_id ') #选择要去重的列 Train=set (train) #去重 DATA=PD. DataFrame (List (train), columns=[' item_id ']) #因为set是无序的, must go through li
, ' Www.bing.com ': 777, ' www.aaa.com ': 1113101, ' www.ccc.net.cn ': 922, ' www.zhanimei.ga ': 29847, ' www.zhanimei.ml ': 40155, ' Www.zhasini.ml ': 373436} I only took the first few, and organized it into a dictionary. Start drawing From pandas import Series,dataframeimport Matplotlib.pyplot as Pltplt.figure (figsize= (8,6), dpi=80) ts = Series (d) Ts.plot (kind= ' Barh ') plt.savefig ('/var/www/jastme/static/images/log.png ') HTML to write the I
This article mainly introduces the pandas data processing basis to filter the specified row or the specified column of the relevant information, the need for friends can refer to the following
The main two data structures of Pandas are: series (equivalent to one row or column of data bodies) and dataframe (a tabular data body equivalent to multiple rows and columns).
This article is intended to facilitate
The following for you to share a pandas implementation of the selection of a specific index of the row, has a good reference value, I hope to be helpful to everyone. Come and see it together.
As shown below:
>>> Import numpy as np>>> import pandas as pd>>> Index=np.array ([2,4,6,8,10]) >>> Data=np.array ([3,5,7,9,11]) >>> DATA=PD. DataFrame ({' num ':d ata},index=index) >>> print (data) num2 910 11
This article mainly introduces the method of pandas to filter data according to the combination condition of several columns, has certain reference value, now share to everybody, the need friend can refer to
Or do you speak with a picture?
A file:
For example, I would like to filter out "design Wells", "put into production Wells", "current well" three columns of data are 11 data, the results are as follows:
Of course, the filter conditions here can
The following for everyone to share a pandas GroupBy group to take the first few lines of the record method, with a good reference value, I hope to be helpful to everyone. Come and see it together.
Directly on the example.
Import Pandas as PD df = PD. DataFrame ({' Class ': [' a ', ' a ', ' B ', ' B ', ' A ', ' a ', ' B ', ' C ', ' C '], ' score ': [3,5,6,7,8,9,10,11,14]})
Df:
class
Below for you to share a pandas multilevel grouping implementation of the method of sorting, with a good reference value, I hope to be helpful to everyone. Come and see it together.
Pandas have groupby grouping functions and sort_values sort functions, but how do you sort the dataframe after grouping them?
in []: DF = PD. DataFrame ((Random.randint), Random.choice ([' Tech ', ' art ', ' Office '), '%dk
SummaryThe use of Python for data analysis, you need to install some common tools, such as numpy,pandas,scipy, etc., during the installation process, often encountered some installation details problems, such as version mismatch, need to rely on the package is not installed properly, etc. This article summarizes the next few necessary installation package installation steps, hoping to help readers, the environment is Windows bit+python2.7.11.A Install
This section describes the basic methods of data in series and Dataframe
Re-index
An important method of Pandas objects is reindex, which is to create a new object that adapts to the new index" "Created on 2016-8-10@author:xuzhengzhu" "" "Created on 2016-8-10@author:xuzhengzhu" " fromPandasImport*Print "--------------obj Result:-----------------"obj=series ([4.5,7.2,-5.3,3.6],index=['D','b','a','C'])PrintobjPrint "--------------obj2 Re
1. In http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python download the corresponding version of the required dependency package;For example my Python version is python3.5, to download the corresponding version of the NumPy dependent package for numpy-1.11.1+mkl-cp35-cp35m-win_amd64.whl,cp35-cp35m is the corresponding python3.5 version,win_amd64 corresponds to a 64-bit system under Windows .2. Save the downloaded dependency package to the Scripts folder in the Python installation folder, my
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.