', 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]
"values.
Table = pd. effect_table (df, index = ["Manager", "Status"], columns = ["Product"], values = ["Quantity", "Price"],
Aggfunc = {"Quantity": len, "Price": [np. sum, np. mean]}, fill_value = 0)
Table
It may be daunting to put all these things together at the same time, but once you start to process the data and add a new project step by step, you will be able to see how it works. My general rule of thumb is that once you use multiple "
row index and the column index can be viewed as a dictionary consisting of series (using a common index). As with other similar data structures (such as data.frame in R), Dataframe row-and column-oriented operations are basically balanced. In fact, the data in Dataframe is stored in one or more two-dimensional blocks (not lists, dictionaries, or other).#-*-encoding:utf-8-*-import NumPy as Npimport
3686000dtype: int64
This is intuitive, but if you want to display the total value as a single row in the table, you still need to make some minor adjustments.
We need to transform the data and convert this series of numbers into DataFrame so that it can be more easily merged into existing data. The T function allows us to change the data arranged by row to the
Introduction
The purpose of this article is to show you how to use pandas to perform some common Excel tasks. Some examples are trivial, but I think showing these simple things is just as important as the complex functions you can find elsewhere. As an extra benefit, I'm going to do some fuzzy string matching to show some little tricks, and show how pandas uses the complete Python module system to do somet
adjustments.
We need to transform the data and convert this series of numbers into DataFrame so that it can be more easily merged into existing data. The T function allows us to change the data arranged by row to the data arranged by column.
df_sum=pd.DataFrame(data=sum_row
attach data rows. We'll use the Dataframe in the previous section to practice concatenation and additional operations on data rowsfunction concat () is a concatenation dataframe, such as a dataframe consisting of 3 rows of data can be concatenated with other data rows in order to reconstruct the original dataframe:Pri
. As the name implies, series is a sequence, similar to a one-dimensional array; The Data frame is the equivalent of a two-dimensional table, similar to a two-dimensional array, with each column being a Series. To locate the elements in the series, Pandas provides the Index object, each with a corresponding index, which is used to mark different elements, which a
Pandas data structures and indexes are Getting Started Pandas must learn the content, here in detail to explain to you, read this article, I believe you Pandas There is a clear understanding of data structures and indexes. first, the dat
', ' C ', ' d ', ' e '])Two discards the item on the specified axisThe data on a row can be discarded by means of a drop , and the parameter is the row indexin [+]: objOUT[64]:1 42 73 54 3Dtype:int64In [All]: New=obj.drop (1)in [+]: NewOUT[66]:2 73 54 3Dtype:int64Three-index, select and filterIn the list and tuple of Python, we can get the information we want by slicing, and we can also get the information by slicing in
How do I delete the list hollow character?Easiest way: New_list = [x for x in Li if x! = ']This section mainly learns the basic operations of pandas based on the previous two data structures.设有DataFrame结果的数据a如下所示: a b cone 4 1 1two 6 2 0three 6 1 6
First, view the data (the method of viewing the object is also applicable for series)1. V
]: result = Df1.append (dicts, Ignore_index=true)
Merge
The pandas Merge method provides a SQL-like memory link operation, which the official website document mentions to be more efficient than other Open-source language data operations such as R.
A comparison of SQL statements can be seen here
The parameters of the merge
On: Column name, the name of the col
Let's create a data frame by hand.[Python]View PlainCopy
Import NumPy as NP
Import Pandas as PD
DF = PD. DataFrame (Np.arange (0,2). Reshape (3), columns=list (' abc ' )
DF is such a dropSo how do you choose the three ways to pick the data?One, when each column already has column name, with DF
Use Python for data analysis _ Pandas _ basic _ 2, _ pandas_2Reindex method of Series reindex
In [15]: obj = Series([3,2,5,7,6,9,0,1,4,8],index=['a','b','c','d','e','f','g', ...: 'h','i','j'])In [16]: obj1 = obj.reindex(['a','b','c','d','e','f','g','h','i','j','k'])In [17]: obj1Out[17]:a 3.0b 2.0c 5.0d 7.0e 6.0f 9.0g 0.0h 1.0i 4.0j 8.0k NaNdtype: float64
If the current va
Below for everyone to share an article Python3 pandas read MySQL data and insert instance, have very good reference value, hope to be helpful to everybody. Come and see it together.
The Python code is as follows:
#-*-Coding:utf-8-*-import pandas as Pdimport pymysqlimport sysfrom sqlalchemy import create_enginedef read_mysql_and_in SERT (): try: conn = pymysql
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 =
Getting started with Python for data analysis--pandas
Based on the NumPy established
from pandas importSeries,DataFrame,import pandas as pd
One or two kinds of data structure 1. Series
A python-like dictionary with indexes and values
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
Face is such a problem, constantly read into a row of data, append to data frame, if using Dataframe, Rbind (), you can find the data is large when the efficiency is significantly lower.The reason is that each bind is a re-copy of the entire
1. Data
Contains a total of 3049 universities nationwide, copied from Renren (for learning exchanges only, not for commercial projects), a script file containing JSON objects that store school information in the form of:
Copy Code code as follows:
var schoollist=[
{
"id": 1,//province ID
"School": [
{
"id": 1001,//school ID
"Name": "\U6E05\U534E\U5927\U5B66"//School Name
}
/....
]//The school in this province
' Name
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.