@ host: port/dbname? Charset = utf8') engine = create_engine ('mysql + mysqldb: // root: 123456@127.0.0.1: 3306/marsapp? Charset = utf8') # query data and convert it to pandas. dataFrame, specifying the index of DataFrame as the id field df = pd in the database. read_ SQL ('select * FROM students ', engine, index_col = 'id') print (df) # modify the data in
. dataFrame ([[1, 2, 3, 4, 16], ['1', '2', '3', '4', 'F'], index = ['data1', 'data2 ']) print (df) # times over 10 times. Check the difference between the result and the expected result. df. apply (lambda x: x * 10) # view the data type df. dtypes # df. loc ['data2 '] = pd. to_numeric (df. loc ['data2 ']) # converts only the data that can be converted. The value that cannot be converted is NaN (Not a Number
([arr, arr], Axis=1) # Connect two arr, in the direction of the row---------------Pandas-----------------------Ser = series () Ser = series ([...], index=[...]) #一维数组, dictionaries can be converted directly to Seriesser.values ser.index Ser.reindex ([...], fill_value=0) #数组的值, index of array, redefine index ser.isnull () pd.isn Ull (Ser) pd.notnull (Ser) #检测缺失数据ser. name= ser.index.name= #ser本身的名字, ser index name Ser.drop (' x ') #丢弃索引x对应的值ser +ser #算术运算ser. Sort_index () Ser.order () # Sort b
= Np.arange (0,100,10)) Df.plot () plt.show ()Here are the parameters to paste:Dataframe also has some parameters for column processing:There are some special graphics from the beginning, which can be compared with the R language when drawing: http://www.cnblogs.com/batteryhp/p/4733474.html.Bar chart#-*-encoding:utf-8-*-import NumPy as Npimport pandas as Pdimport Matplotlib.pyplot as Pltfrom pandas import Series,dataf rame# generated line graph in code plus kind = ' bar ' (vertical bar) or (hor
keys that distinguish a data group
The keys mentioned above can be used to add key to the merged table to differentiate different table data sources 1.5.1 can be implemented directly with key parameters
In [to]: result = Pd.concat (frames, keys=[' x ', ' y ', ' z '])1 1 1
1.5.2 incoming dictionaries to increase the grouping keys
in [n]: pieces = {' X ': df1, ' y ': df2, ' z ': df3} in
[[]: result = Pd.concat (pieces)1 2 3 1 2 3 1 2 3
1.6 Add a new line to the
environments because the Idle format is more attractive on blogs.Data Normalization
First, the scoring data is read from the Ratings.dat into a dataframe:
>>> import pandas as PD
>>> from pandas import series,dataframe
>>> rnames = [' user_id ', ' movie_id ', ' rating ', ' timestamp ']
>>> ratings = pd.read_table (R ' Ratings.dat ', sep= ':: ', Header=n
"). Text: Print (team_id, team_name), Data.append ([team_i D,team_name]) self.team_list = Data #self. Team_list =PD. DataFrame (data, columns=[' team_name ', ' team_id ']) #self. Team_list.to_excel (' National Team id.xlsx ', Index=false) T_team_data (self, team_id,team_name): 74 75 "" to get a match data for a national team. TODO: No paging Python learning Exchange Group: 125240963, the group daily share o
Create an empty Data frame with date index:ImportPandas as PDdefTest_run (): start_date='2017-11-24'End_data='2017-11-28'dates=Pd.date_range (start_date, end_data) df1=PD. DataFrame (index=dates)Print(DF1)"""Empty dataframecolumns: []index: [2010-01-22 00:00:00, 2010-01-23 00:00:00, 2010-01-24 00:00:00, 2010-01-25 00:00:00 , 2010-01-26 00:00:00]"""Now we want to load spy.csv and get ' ADJ Close ' column val
DirectoryRead data display data display rows and columns view data format dtpyes display column name add default column name Display data 5 rows after display of data unique values skipped line I of the file does not read the missing value recognition data cleaning processing null value change data format change column name remove duplicate value replace value in list Data preprocessing to data sorting data data extraction by label extraction by position extraction by label and position extracti
=pl.cm.Paired)
Pl.title (Clf_name)
Pl.legend (loc="best")
data = Open ("Cows_and_wolves.txt"). Read ()
data = [Row.split (' \ t ') for row in Data.strip (). Split (' \ n ')]
Animals = []
For Y, row in Enumerate (data):
For x, item in enumerate (ROW):
# x ' s is cows, O ' s is Wolves
If item in [' O ', ' x ']:
Animals.append ([x, Y, item])
DF = PD. DataFrame (Animals, co
The following is transferred from the analysis of the college, the original text follow-up and on the index value in the process of merging, students need to learn to directly see the original
To introduce you to the connection (CONCAT) and append (append) in the dataset merge method, first do some preparation work:
1. Import Pandas Library and NumPy library:
Import pandas as PD
import NumPy as NP
2. Define a MAKE_DF function to generate the sample d
This is a creation in
Article, where the information may have evolved or changed.
This series of articles is mainly for TIKV community developers, focusing on tikv system architecture, source structure, process analysis. The goal is to enable developers to read, to have a preliminary understanding of the TIKV project, and better participate in the development of TIKV.
TIKV is a distributed KV system that uses the Raft protocol to ensure strong data consistency, while supporting distributed trans
Insert Column#-*-Coding:utf-8-*-"""Created on Mon Mar 09 11:21:02 2015@author: [Email protected]"""Print U "python data analysis \ n"Import Pandas as PDImport NumPy as NP#构造商品销量数据MYDF = PD. DataFrame ({u ' product area code ': [1,1,3,2,4,3],u ' Product A ': Np.random.randint (0,1000,size=6), U ' product B ': Np.random.randint (0,1000, size=6), U ' product C ': Np.random.randint (0,1000,size=6)})allsales=myd
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.