pandas 将表读入DataFrame
示例
具有页眉,页脚,行名和索引列的表文件:
文件:table.txt
This is a header that discusses the table file to show space in a generic table file index name occupation 1 Alice Salesman 2 Bob Engineer 3 Charlie Janitor This is a footer because your boss does not understand data files
码:
import pandas as pd
# index_col=0 tells pandas that column 0 is the index and not data
pd.read_table('table.txt', delim_whitespace=True, skiprows=3, skipfooter=2, index_col=0)输出:
name occupation index 1 Alice Salesman 2 Bob Engineer 3 Charlie Janitor
没有行名或索引的表文件:
文件:table.txt
Alice Salesman Bob Engineer Charlie Janitor
码:
import pandas as pd
pd.read_table('table.txt', delim_whitespace=True, names=['name','occupation'])输出:
name occupation 0 Alice Salesman 1 Bob Engineer 2 Charlie Janitor
所有选项都可以在此处的熊猫文档中找到
热门推荐
1 泰迪狗狗如何训练
3 狗狗训练图
5 狗狗训练方法
6 训练狗狗不咬人
8 敏捷训练狗狗
10 训练狗狗吃饭
11 泰迪狗狗训练
12 狗狗从多大开始训练
13 狗狗训练学校费用
14 怎么去训练狗狗
15 狗狗训练狗狗
16 狗狗训练教程
17 训练狗狗装死
18 泰迪狗狗的训练方法