Import NumPy as NP from
Pandas import dataframe
import pandas as PD
Df=dataframe (Np.arange () reshape (3,4 ), index=[' One ', ' two ', ' THR '],columns=list (' ABCD ')
df[' A ' #取a列
df[[' A ', ' B ']] #取a, column B
#ix可以用数字索引, You can also use index and column indexes
df.ix[0] #取第0行
df.ix[0:1] #取第0行
df.ix[' one ':
Tags: Establish connection copy TOC UTF8 identify Data-nec LDB serviceWrites pandas's dataframe data to the MySQL database + sqlalchemy [Python]View PlainCopyprint?
IMPORTNBSP;PANDASNBSP;ASNBSP;PDNBSP;NBSP;
fromsqlalchemyimportcreate_engine
NBSP;NBSP;
# #将数据写入mysql的数据库, However, you need to establish a connection through Sqlalchemy.create_engine, and the character encoding i
', DF ['v1']) #2 indicates the insert position, and V6 indicates the column name, DF ['v1 '] is the inserted value print ('insert column:') print (DF, '\ n') print (' * 50)
4. General selection methods:
Operation Method
Method
Result
Select a column
Def [col]
Sequence
Select a row using column tags
DF. Loc [col]
Sequence
Select a row by location
DF. icol [2]
Sequence
Line Cutting
DF [5: 10]
Data box
convert to a format that can be found using XPath
= Doc.xpath ('//table ')
find all the tables in the document and return a list
Let's look at the source code of the Web page and find the form that needs to be retrieved
The first behavior title of the table, the following behavior data, we define a function to get them separately:
def _unpack (Row, kind= ' TD '):
ELTs = Row.xpath ('.//%s '%kind)
# Get data based on label type return
[Val.text_content () For Val in ELTs]
# Use
Python traversal pandas data method summary, python traversal pandas
Preface
Pandas is a python data analysis package that provides a large number of functions and methods for fast and convenient data processing.
DF1 is the test data for the DATAFRAME structure:The DF1 data is read from the TEST.XLSX document, using the sample code as follows:#-*-Coding:utf-8-*-import Tushare as Tsimport pandas as Pddf = Pd.read_excel (' test.xlsx ') df1 = Df.head (Ten) #dataframe按索引In ascending order, the default is ascending #print df1.sort_index () #
This question mainly writes the method of sorting series and dataframe according to index or value
Code:
#coding =utf-8
Import pandas as PD
import numpy as NP
#以下实现排序功能.
SERIES=PD. Series ([3,4,1,6],index=[' B ', ' A ', ' d ', ' C '])
FRAME=PD. Dataframe ([[2,4,1,5],[3,1,4,5],[5,1,4,2]],columns=[' B ', ' A ', ' d ', ' C '],index=[' one ', ' two ', ' three '])
pr
The following for you to share a Python data Analysis Library Pandas basic operation method, has a good reference value, I hope to help you. Come and see it together.
What is Pandas?
Is it it?
。。。。 Apparently pandas is not so cute as this guy ....
Let's take a look at how Pandas's official website defines itself:
PandasPandas is a popular open source Python project that takes the name of panel data and Python data analysis.Pandas has two important data structures: Dataframe and seriesThe dataframe of PANDAS data structurePandas's DATAFRAME
economics, and it also provides a pandas for the panel.
3. Data structure: Series: One-dimensional array, similar to one dimension array in NumPy. The two are similar to Python's basic data Structure list, and the difference is that the elements in the list can be different data types, while the array and series only allow the same data type to be stored, which makes it more efficient to use memory and improve efficiency. Time-series: A Series that i
namePrint Food_info.columns #打印dataframe数据类型下的各列列名.5) Dataframe sample number and number of indicatorsPrint Food_info.shape #打印dataframe形状, a few rows of columns, where the number of rows is the number of samples, the number of columns is the number of indicators.6) Pandas fetch dataFetch data by sample (ROW):
merage#Pandas provides a method Merge (left, right, how= ' inner ', On=none, Left_on=none, Right_on=none, left_index=false, Right_index=false, sort= True, suffixes= (' _x ', ' _y '), Copy=true, Indicator=false)As a fully functional and powerful language, the merge () in Python's pandas library supports a variety of internal and external connections.
Left and right: two different
. Data structure:Series: A one-dimensional array, similar to a one-dimensional array in NumPy. The two are similar to the Python basic data Structure list, the difference is that the elements in the list can be different data types, and the array and series only allow the same data types to be stored, so that more efficient use of memory, improve the efficiency of operations. Time-series: A Series that is indexed in time.
Data conversionDelete duplicate elements The duplicated () function of the Dataframe object can be used to detect duplicate rows and return a series object with the Boolean type. Each element pairsshould be a row, if the row repeats with other rows (that is, the row is not the first occurrence), the element is true, and if it is not repeated with the preceding, the metaThe vegetarian is false.A Series object that returns an element as a Boolean is of
often press SHIFT + TAB + TAB while using Pandas. When the pointer is placed in the name or in parentheses in the valid Python code, the object pops up with a small scroll box to display its document. This small box is very useful to me because it is not possible to remember all the parameter names and their input types.Press SHIFT + TAB + TAB to open the Stack mode documentYou can also be in "." Then pres
way, and filtering through a Boolean array.However, it is important to note that because the index of the Pandas object is not limited to integers, it is included at the end when using a non-integer as the tile index.>>> fooa 4.5b 7.2c -5.3d 3.6dtype:float64>>> bar0 4.51 7.22 -5.33 3.6dtype:float64>>> foo[:2]a 4.5b 7.2dtype:float64>>> bar[:2]0 4.51 7.2dtype:float64>>> foo[: ' C ']a 4.5b 7.2c -5.3dtype:float64
This time for you to bring Python read text data and into the Dataframe format of the method in detail, Python read the text data and conversion to Dataframe note what, the following is the actual case, take a look.
In the technical question and answer to see a question like this, feel relatively common, just open an
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.