import pandas as pd
from pandas import Series, DataFrame
data = {"name":["yahoo","google","facebook"], "marks":[200,400,800], "price":[9, 3, 7]}
f1 = DataFrame(data)
print(f1)
marks name price
0200 yahoo 91400 google 32800 facebook 7
添加索引
# 按指定顺序排列,并添加索引
f2 = DataFrame(data, columns = ['price', 'name', 'marks', 't'], index = ['a', 'b', 'c'])
print(f2)
price name marks t
a 9 yahoo 200 NaN
b 3 google 400 NaN
c 7 facebook 800 NaN
# 精准输出print(f2['name']['a']) #yahoo
读取csv
import pandas as pd
from pandas import Series, DataFrame
marks = pd.read_csv('marks.csv')
print(marks)
读取excel
xlsx = pd.ExcelFile('.\marks.xlsx')
print(xlsx.sheet_names)
sheet_1 =xlsx.parse('Sheet1')
print(sheet_1)
['Sheet1', 'Sheet2', 'Sheet3', 'Sheet4', 'Sheet5', 'Sheet6']
name physics python math english
0 Google 10010025121 Facebook 455444882 Twitter 547613913 Yahoo 5445226100
numpy
import numpy as np
x = [12,4,2,4,23,121]
y = [32,21,223,43,12,55]
nx = np.array(x)
ny = np.array(y)
print(nx/ny**2)
#数据筛选就这么简单print(nx[nx>12])#[ 23 121]
# 二维数组
x = [12,43,23,42,23,11]
y = [32,21,23,43,12,55]
np_2d = np.array([x,y])
print(np_2d)
# 输出个坐标值print(np_2d[0,1])
# 输出第二行print(np_2d[1])
# 切片输出(含前不含后)print(np_2d[:,1:3])
print(np_2d[1:,1:2])