Commonly used: read_csv, read_excel in pandas
Table of contents
2. Headers and names about column names
3. Display the data read from the file
Common parameters:
1. Filepath path introduction
The computer directly copies the path in the form: path=G:\download file\data\users.dat
But python only recognizes: "/" and cannot directly recognize "\"
Then there are the following two methods
(1) path=r"G:\Download File\data\users.dat"
(2) path=path.replace("\\","/") (replace "\" with "/")
2. Headers and names about column names
· header: the default is inter (identified by the system itself);
If header=0, the first line is the column name; if header=3, the fourth line is the column name; header=None means the column name is customized.
· Custom column names use parameter names to accept array
3. Display the data read from the file
import pandas as pd
import numpy as np
df=pd.read_excel(r'F:\个人嘿嘿嘿\北师大BNU\研一上-课业资料\时间序列\作业2\timeseries17.xlsx',header=0)
#如何将表中所有数据显示全?
#显示所有列
pd.set_option('display.max_columns',None)
#显示所有行
pd.set_option('display.max_rows',None)
#设置value的显示长度为100,默认为50
pd.set_option('max_colwidth',100)
#输完以上代码,再读取df即可得到所需数据
#测试显示前五行or后五行
df.head() #可设置具体参数显示前n行
df.tail()