join and specify Keys (row index) \ r \ n ', concat ([df1,df2],keys=[' A ', ' B ']) # Here are the duplicate data print ' go back \ r \ n ', concat ([df1,df2],ignore_index=true). Drop_duplicates ()The output is:Internal connection by Axis City rank City rank0 Chicago 1 Chicago San Francisco 2 Boston New York City 3 Los Angeles 5 outer Joins and assign keys (row index) City Ranka 0 Chicago 1 1 San F
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
have the following advantages:
Faster (once set)
Self-explanation (by checking the code, you will know what it has done)
Easy to generate reports or emails
More flexible, because you can define custom Aggregate functions
Read in the data
First, let's build the required environment.
If you want to continue with me, you can download this Excel file.
Import pandas as pd
Import numpy as np
Vers
Http://www.cnblogs.com/batteryhp/p/5006274.htmlPandas is the preferred library for subsequent content in this book. The pandas can meet the following requirements:
Data structure with automatic or explicit data alignment by axis. This prevents many common errors caused by data misalignment and
At the time of data processing, especially in the big data contest, often encounter a problem is that multiple forms of merging problems, such as a form has user_id and age two fields, another form has user_id and sex two fields, to merge these two tables into only user_id, Age, sex three fields of the table what to do, the ordinary stitching is not possible, bec
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
']df_obj[' user number '].isin (alist) #将要过滤的数据放入字典中, uses Isin to filter the data, returns the row index and the results of each row filter, and returns if the match is turedf_obj[df_obj[' user number '].isin (alist)] #获取匹配结果为ture的行Filter data using Dataframe blur (like in sql):df_obj[df_obj[' package '].str.contains (R '. * Voice cdma.* ')] #使用正则表达式进行模糊匹配, * match 0 or unlimited, match 0 or 1 timesData c
The source of this article:Python for Data Anylysis:chapter 5Ten mintues to Pandas:http://pandas.pydata.org/pandas-docs/stable/10min.html#min1. Pandas IntroductionAfter several years of development, pandas has become the most commonly used package in Python processing data.
'); Pd.read_excel (' foo.xlsx ', ' Sheet1 ', Index_col=none, na_values=[' na ']) #写入读取excel数据, Pd.read_ The data read by Excel is stored in dataframe form (' Foo.h5 ', ' df ');pd. READ_HDF (' foo.h5 ', ' df ') #写入读取HDF5数据
8) Aggregate data using pandas (like group by or having in SQL):
data_obj[' User ID '].groupby (data_obj[' branch-maintenance line ') data_o
Pandas is the preferred library for subsequent content in this book. The pandas can meet the following requirements:
Data structure with automatic or explicit data alignment by axis. This prevents many common errors caused by data misalignment and
Most of the students who Do data analysis start with excel, and Excel is the most highly rated tool in the Microsoft Office Series.But when the amount of data is very large, Excel is powerless, python Third-party package pandas greatly extend the functionality of excel, the entry takes a little time, but really is the necessary artifact of big
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
The use of horizontal data merging merge and vertical data merging Rbind in R languageWe often encounter two data frames that have the same time or observation values, but these columns are different. The way to deal with this is to useMerge (x, y, by.x =, By.y =, all =) fun
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.