![](https://img-blog.csdnimg.cn/20190918140145169.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
pandas函数实例
pandas函数实例
陆百亿
每天CV一点点,技术能力又有长进。总有一天能转行当程序员。
展开
-
【pandas之DataFrame相关函数】query()函数
**DataFrame.query(expr, inplace=False, **kwargs)[source]Query the columns of a DataFrame with a boolean expression.通过布尔表达式进行查询**待读取文件预览:运行结果:原创 2022-06-24 16:19:05 · 2874 阅读 · 1 评论 -
【pandas之DataFrame相关函数】where()函数,mask()函数
**pandas.DataFrame.where():Replace values where the condition is False.将不符合条件的值,替换成指定值。pandas.DataFrame.mask():Replace values where the condition is True…将符合条件的值,替换成指定值。原创 2022-06-14 15:53:41 · 781 阅读 · 0 评论 -
【pandas之DataFrame相关函数】isin()函数
isin():Whether each element in the DataFrame is contained in values判断元素是否在 传入的参数values中。原创 2022-06-14 15:10:31 · 688 阅读 · 0 评论 -
【pandas之DataFrame相关函数】pop()函数
pop():指定列名,删除原df中的指定列,并将该列返回为series原创 2022-06-13 16:46:14 · 1307 阅读 · 1 评论 -
【pandas之DataFrame相关函数】迭代函数iteritems(),iterrows(),itertuples()
iteritems()在列上迭代,返回由“列名”和“列值构成的Series”所组成的tuple。iterrows()在行上迭代,返回由“行名”和“行值构成的Series”所组成的tuple。itertuples()在行上迭代,返回设置了名称的tuple。待读取文件预览:...原创 2022-06-13 16:21:36 · 1076 阅读 · 0 评论 -
【pandas之DataFrame相关函数】insert()函数
dataframe.insert()函数。在指定的列位置插入一列原创 2022-06-13 15:22:24 · 833 阅读 · 0 评论 -
【pandas之DataFrame相关函数】loc()函数、iloc函数
loc()根据行列的名称,查询对应行列。待读取文件预览: import pandas as pd# 读取excelfile_path = r'C:\Users\123\Desktop\pandastest\example.xlsx'df = pd.read_excel(file_path, sheet_name=0, header=0, skipfooter=0)# 预览前5行print(df.head(5))# 通过行列的名称、或者行列名称数组,获取数据'''查询行'''#原创 2022-04-15 12:01:04 · 3151 阅读 · 0 评论 -
【pandas之DataFrame相关函数】at()函数,iat()函数
待读取文件预览: 代码:import pandas as pd# 读取excelfile_path = r'C:\Users\123\Desktop\pandastest\example.xlsx'df = pd.read_excel(file_path, sheet_name=0, header=0, skipfooter=0)# 预览前5行print(df.head(5))# 获取index = 2,column =“编号”的值x = df.at[2, '编号']prin原创 2022-04-15 11:22:02 · 3828 阅读 · 0 评论 -
【pandas之DataFrame相关函数】astype()函数
待读取文件预览: 代码:import pandas as pd# 读取excelfile_path = r'C:\Users\123\Desktop\pandastest\example.xlsx'df = pd.read_excel(file_path, sheet_name=0, header=0, skipfooter=0)# 查询df的数据类型print(df.dtypes)df2 = df.astype('object', copy=True, errors='raise原创 2022-04-12 11:54:18 · 2074 阅读 · 0 评论 -
【pandas之DataFrame相关函数】select_dtypes函数:根据数据类型,查询列
待读取文件预览: 代码:import pandas as pd#读取excelfile_path = r'C:\Users\123\Desktop\pandastest\example.xlsx'df = pd.read_excel(file_path, sheet_name=0, header=0, skipfooter=0)#查询df的数据类型print(df.dtypes)#根据数据类型查询列print(df.select_dtypes('int64'))print(d原创 2022-04-12 11:41:55 · 1150 阅读 · 0 评论 -
【pandas之DataFrame相关函数】columns函数、dtypes函数、info()函数、size函数
代码:import pandas as pdfile_path = r'C:\Users\123\Desktop\pandastest\example.xlsx'df = pd.read_excel(file_path, sheet_name=0, header=0, skipfooter=0)print('df.size:')print(df.size)print('df.columns:')print(df.columns)print('df.dtypes:')print(df原创 2022-04-12 11:34:14 · 2021 阅读 · 0 评论 -
【pandas之输入输出函数】pandas.read_excel 和 pandas.DataFrame.to_excel 读取和导出excel
pandas.read_excel官方文档地址:https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html待读取文件预览:代码:import pandas as pdfile_path = r'C:\Users\123\Desktop\pandastest\example.xlsx'df = pd.read_excel(file_path, sheet_name=0, header=0,原创 2022-04-11 16:07:29 · 700 阅读 · 0 评论