获取DataFrame的行数和列数
df为DataFrame一个变量实例
行数:df.shape[0] 或 len(df)
列数:df.shape[1] 或 (len(df.columns))
写入csv文件中header和index参数的作用
DataFrame.to_csv(path_or_buf,sep,na_rep,columns,header,index,index_label,mode,encoding)
参数 | 类型 | 说明 |
---|---|---|
path_or_buf | 字符串 | 文件路径+文件名 |
sep | 字符串 | 分隔符 默认为"," |
na_rep | ----- | ----- |
columns | ----- | ----- |
header | bool类型 | header=True(默认) 把原字段名写入文件,header=False 不把原字段名写入文件 |
index | bool类型 | index=True(默认) 把原行名(索引)写入文件,index=False 不把原行名(索引)写入文件 |
index_label | ----- | ----- |
mode | ----- | ----- |
encoding | 特定字符串 | “UTF-8” “GBK” “GB2312” “ANSI” |