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
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
install:python27\scripts, run Python ez_setup.py4.3) Install pip:python27\scripts, run Easy_install pip5. MatplotlibIn addition to the above 4 items, it is also important to note:1) Dateutil 1.1 or laterProvides extensions to Python datetime handling. If using PIP, Easy_install or installing from source, the installer would attempt to download and install from python_dateutil P YPI.: PYTHON_DATEUTIL-2.4.2-PY2.PY3-NONE-ANY.WHL2) pyparsingRequired for matplotlib’s mathtext math rendering support.
Operating environment: PYTHON3.6+WINDOWS64 bit1. Install PIP(1) If you have the option to tick about PIP when installing python3.6, the installation file with PIP will be available in python3,6Installation Method:Main: http://www.lfd.uci.edu/~gohlke/pythonlibs/Follow these steps to install: use a command prompt (cmd), preferably running as an administrator. Execute the CD command in CMD to the Python installation directory, under the Execute CD command to its scripts folder, under this folder, t
This article and everyone to share is mainly pandasLibrary Common FunctionsRelated content, come together to look at it, hope to everyone learn pandas helpful. 1. DataFrameHandling Missing valuesPandas. Dataframe.dropna Df2.dropna (axis=0, how= ' any ', subset=[u ' ToC '), inplace=True)put inTocrows with missing values are removed 2.calculate duplicate rows based on a dimensionPandas. Dataframe.duplicated Printdf.duplicated ([' Name ']). Value_counts
1. Create a dataframe from a dictionary>>>ImportPandas>>> dict_a = {'user_id':['Webbang','Webbang','Webbang'],'book_id':['3713327','4074636','26873486'],'rating':['4','4','4'],'mark_date':['2017-03-07','2017-03-07','2017-03-07']}>>> df = Pandas. DataFrame (DICT_A)#Create a dataframe from a dictionary>>> DF#The created DF column names are sorted alphabetically by default, and the order in the dictionary is not the same, the dictionary is ' user_id ', '
Data filtering and sorting------Explore 2012 Euro Cup dataRelated data See (github)Step 1-Import the Pandas libraryimport Pandas as PDStep 2-Data set" ./data/euro2012.csv " # Euro2012.csvStep 3-Name the dataset euro12Euro12 = pd.read_csv (path2) euro12.tail ()Output:
Team
goals
Shots on target
Shots off target
Shooting accuracy
% goals-to-shotsTotal
Shots
Here is still to recommend my own built Python development Learning Group: 483546416, the group is the development of Python, if you are learning Python, small series welcome you to join, everyone is the software Development Party, not regularly share dry goods (only Python software development-related), Including a copy of my own 2018 of the latest Python advanced materials and high-level development tutorials, welcome to the next step and into the small partners who want to dive into python.An
Pandas mainly has 4 of the time-related types. Timestamp, Period, Datetimeindex,periodindex.ImportPandas as PDImportNumPy as NP##TimestampPd. Timestamp ('9/1/2016 10:05am')#output:timestamp (' 2016-09-01 10:05:00 ')##PeriodPd. Period ('1/2016')#output:period (' 2016-01 ', ' M ')Pd. Period ('3/5/2016')#output:period (' 2016-03-05 ', ' D ')##DatetimeindexT1 = PD. Series (List ('ABC'), [PD. Timestamp ('2016-09-01'), PD. Timestamp ('2016-09-02'), PD. Time
Delete one or more columns of Pandas Dataframe:method One : Direct del df[' Column-name ']method Two : Using the Drop method, there are three types of equivalent expressions:1. df= df.drop (' column_name ', 1);2. Df.drop (' column_name ', Axis=1, Inplace=true)3. Df.drop ([df.columns[[0,1, 3]], axis=1,inplace=true) # Note:zero indexedNote : Usually there is a inplace optional parameter that modifies the original array and returns a new array. If set to
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.