一、Pandas数据结构
1、import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
2、S1=pd.Series([‘a’,’b’,’c’]) series是一组数据与一组索引(行索引)组成的数据结构
3、S1=pd.Series([‘a’,’b’,’c’],index=(1,3,4)) 指定索引
4、S1=pd.Series({1:‘a’,2:’b’,3:’c’}) 用字典形式指定索引
5、S1.index()返回索引
6、S1.values()返回值
7、Df=pd.DataFrame([‘a’,’b’,’c’])dataframe是一组数据与两组索引(行列索引)组成的数据结构
8、Df=pd.DataFrame([[a,A],[b,B],[c,C]],columns=[‘小写’,’大写’],index=[‘一’,’二’,’三’])
Columms 为列索引,index为行索引
9、pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider清华镜像
10、data={‘小写’:[‘a’,’b’,’c’],’大写’:[‘A’,’B’,’C’]}传入字典
Df=Pd.DataFrame(data)
11、Df.index() df.columns()
二、读取数据
12、df=pd.read_excel(r’C:\user\...xlsx’,sheet_name=’sheet1’) 或
Pd.read_excel(r’C:\user\...xlsx’,sheet_name=0) 读取excel表
13、Pd.read_excel(r’C:\user\...xlsx’,index_col=0,header=0)
index_col指定行索引,header指定列索引
14、pd.read_excel(r’C:\user\...xlsx’,usecols=[0,1])导入指定列,不能有index_col和header
15、pd.read_tablel(r’C:\user\...txt’,sep=’ ’)导入txt文件,sep指定分隔符是什么
16、df.head(2)展示前两行,默认展示前5行
17、df.shap显示数据几行几列,不包含行和列索引