【第6章】pandas分块读取文件(nrows、chunksize)

1、pandas全局设置显示最多的行数

#7、设置显示行数为10行
pd.options.display.max_rows=10
# 7-1、读取行只有10条
pd.read_csv(Path('../源代码/examples/ex6.csv'))
"""
		one			two			three		four	key
0	0.467976	-0.038649	-0.295344	-1.824726	L
1	-0.358893	1.404453	0.704965	-0.200638	B
2	-0.501840	0.659254	-0.421691	-0.057688	G
3	0.204886	1.074134	1.388361	-0.982404	R
4	0.354628	-0.133116	0.283763	-0.837063	Q
...	...	...	...	...	...
9995	2.311896	-0.417070	-1.409599	-0.515821	L
9996	-0.479893	-0.650419	0.745152	-0.646038	E
9997	0.523331	0.787112	0.486066	1.093156	K
9998	-0.362559	0.598894	-1.843201	0.887292	G
9999	-0.096376	-1.012999	-0.657431	-0.573315	0
10000 rows × 5 columns
"""

2、指明读取多少行(nrows

# 7-2、指明读取多少行(nrows)
pd.read_csv(Path('../源代码/examples/ex6.csv'),nrows=5)
"""
		one			two			three		four	key
0	0.467976	-0.038649	-0.295344	-1.824726	L
1	-0.358893	1.404453	0.704965	-0.200638	B
2	-0.501840	0.659254	-0.421691	-0.057688	G
3	0.204886	1.074134	1.388361	-0.982404	R
4	0.354628	-0.133116	0.283763	-0.837063	Q
"""

3、分块读取(chunksize