python pandas operation

 


# Pandas installation
# pip install pandas pip install xlrd ( xls read)

Import PANDAS PD AS

# loads excel file
# pd.read_excel (filename, sheet_name, header, nrows, usecols)
# filename file path, sheet_name need to read data form name index from 0, header header, the default is 0, the first row, the number of lines to be read nrows, usecols hunting technique to read
V = pd.read_excel ( "ceshi.xlsx")
Print ( V)
v = pd.read_excel ( "ceshi.xlsx", nrows = 2)
Print (V)

after the # obtain form data, reads the specified plurality of data lines Sample, randomly
v = pd.read_excel ( "ceshi.xlsx" )
v_many = v.sample (2) .values
Print (v_many)
Print ( "-----------------")

# read a data
s = v [ "name"] .values
Print (S)
Print ( "-----------------")

# read the specified one-way, there will be a list of data inside
# data = df.loc [0].values ​​# 0 is the first row, and read the data does not contain header
v.loc = S [0] .values
Print (S)
Print ( "-----------------")

# read the specified multiple rows, the nested list data
# data = df.loc [start line: end line] .values # 0 is the first row, and read the data does not contain header
S1 = v.loc [2:. 3]
S = v.loc [2:. 3] .values
Print (S1)
Print ( "-----------------")
Print (S)
Print ( "--------------- - ")
# read the specified ranks
# data = df.iloc [1,0] # of the second row, first column
Data = v.iloc [1,0]
Print (Data)


Guess you like

Origin www.cnblogs.com/yago/p/11443804.html