【pandas】使用笔记

记录贴。

import pandas as pd

文件

可结合参考:【album】Python使用笔记 - 博客园 (cnblogs.com)

.read_excel

Read an Excel file into a pandas DataFrame.
Supports xls, xlsx, xlsm, xlsb, odf, ods and odt file extensions read from a local filesystem or URL. Supports an option to read a single sheet or a list of sheets.

cname = ['姓名', '身高', '血型']    # 选择要用的列
dats = pd.read_excel(file, usecols=cname, engine='openpyxl')  

.ExcelWriter

Class for writing DataFrame objects into excel sheets.
Default is to use xlwt for xls, openpyxl for xlsx, odf for ods. See DataFrame.to_excel for typical usage.
The writer should be used as a context manager. Otherwise, call close() to save and close any opened file handles.

.read_csv

Read a comma-separated values (csv) file into DataFrame.
Also supports optionally iterating or breaking of the file into chunks.

data_txt = pd.read_csv('test.txt', sep='\t', header=None)   # DataFrame
# data_txt.iloc[0]
data1_txt = pd.read_csv('test.txt', sep='\t', header=None).values  # array
# data1_txt[0]
posted @ 2022-01-29 15:56  Skye_Zhao  阅读(67)  评论(0编辑  收藏  举报