本人NLP研究方向,个人pandas学习笔记,供参考。
http://c.biancheng.net/pandas/
https://www.bilibili.com/video/BV1UJ411A7Fs?spm_id_from=333.999.0.0
csv tsv txt | pd.read_csv |
---|---|
excel | pd.read_excel |
mysql | pd.read_sql |
pandas.read_csv(filepath_or_buffer, sep=',', delimiter=None, header='infer',names=None, index_col=None, usecols=None) #语法格式
import pandas as pd
#需要注意文件的路径
df=pd.read_csv("C:/Users/Administrator/Desktop/person.csv")
print (df)
查看前几行 | df.head(n) |
---|---|
查看后几行 | df.tail(n) |
查看数据形状,返回行数、列数 | df.shape |
查看列名/行名 | df.columns /df.index |
查看类型 | df.dtypes |
import pandas as pd
data = "xxx.txt"
df = pd.read_csv(data,sep="/t",header=None,names=['xx','xxx'])#可以自己命名names
pd.read_excel(io, sheet_name=0, header=0, names=None, index_col=None,
usecols=None, squeeze=False,dtype=None, engine=None,
converters=None, true_values=None, false_values=None,
skiprows=None, nrows=None, na_values=None, parse_dates=False,
date_parser=None, thousands=None, comment=None, skipfooter=0,
convert_float=True, **kwds)
DataFrame.to_excel(excel_writer, sheet_name='Sheet1', na_rep='', float_format=None, columns=None, header=True, index=True, index_label=None, startrow=0, startcol=0, engine=None, merge_cells=True, encoding=None, inf_rep='inf', verbose=True, freeze_panes=None)
import pandas as pd
file = '课程目标达成.xls'
data = pd.read_excel(io=file, sheet_name='课程目标')
import pymysql
conn = pymysql.connect(host='127.0.0.1',user='root',password='123456',database='teat',charset='utf8')
df = pd.read_sql("select * from crazyant_pvuv",con=conn)