pandas (二)数据的查看、检查、统计、属性

查看、检查、统计、属性

查看、检查

df.head(n) # 查看 DataFrame 对象的前n行
df.tail(n) # 查看 DataFrame 对象的最后n行
df.sample(n) # 查看 n 个样本,随机
df.shape # 查看行数和列数
df.info() # 查看索引、数据类型和内存信息
df.describe() # 查看数值型列的汇总统计
df.dtypes # 查看各字段类型
df.axes # 显示数据行和列名
df.mean() # 返回所有列的均值
df.mean(1) # 返回所有行的均值,下同
df.corr() # 返回列与列之间的相关系数
df.count() # 返回每一列中的非空值的个数
df.max() # 返回每一列的最大值
df.min() # 返回每一列的最小值
df.median() # 返回每一列的中位数
df.std() # 返回每一列的标准差
df.var() # 方差
s.mode() # 众数
s.prod() # 连乘
s.cumprod() # 累积连乘,累乘
df.cumsum(axis=0) # 累积连加,累加
s.nunique() # 去重数量,不同值的量
df.idxmax() # 每列最大的值的索引名
df.idxmin() # 最小
df.columns # 显示所有列名
df.team.unique() # 显示列中的不重复值
# 查看 Series 对象的唯一值和计数, 计数占比: normalize=True
s.value_counts(dropna=False)
# 查看 DataFrame 对象中每一列的唯一值和计数
df.apply(pd.Series.value_counts)
df.duplicated() # 重复行
df.drop_duplicates() # 删除重复行
# set_option、reset_option、describe_option 设置显示要求
pd.get_option()
# 设置行列最大显示数量,None 为不限制
pd.options.display.max_rows = None
pd.options.display.max_columns = None
df.col.argmin() # 最大值[最小值 .argmax()] 所在位置的自动索引
df.col.idxmin() # 最大值[最小值 .idxmax()] 所在位置的定义索引

累计统计

ds.cumsum() # 前边所有值之和
ds.cumprod() # 前边所有值之积
ds.cummax() # 前边所有值的最大值
ds.cummin() # 前边所有值的最小值
# 窗口计算(滚动计算)
ds.rolling(x).sum() #依次计算相邻x个元素的和
ds.rolling(x).mean() #依次计算相邻x个元素的算术平均
ds.rolling(x).var() #依次计算相邻x个元素的方差
ds.rolling(x).std() #依次计算相邻x个元素的标准差
ds.rolling(x).min() #依次计算相邻x个元素的最小值
ds.rolling(x).max() #依次计算相邻x个元素的最大值
  • 7
    点赞
  • 56
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 可以使用 `help()` 函数或者 `?` 符号来查看 Pandas Series 的参数。 1. 使用 `help()` 函数: ```python import pandas as pd # 创建一个 Pandas Series s = pd.Series([1, 2, 3]) # 使用 help() 函数查看 Series 的参数 help(pd.Series) ``` 运行结果: ``` Help on class Series in module pandas.core.series: class Series(pandas.core.generic.NDFrame) | Series(data=None, index=None, dtype=None, name=None, copy=False, fastpath=False) | | One-dimensional ndarray with axis labels (including time series). | | Labels need not be unique but must be a hashable type. The object supports | both integer- and label-based indexing and provides a host of methods for | performing operations involving the index. Statistical methods from | ndarray have been overridden to automatically exclude missing data (currently | represented as NaN) | | Method resolution order: | Series | pandas.core.generic.NDFrame | pandas.core.base.PandasObject | pandas.core.accessor.DirNamesMixin | pandas.core.base.StringMixin | builtins.object | | Methods defined here: | | __array__(self, dtype=None) -> numpy.ndarray | Return an array representing the values in the Series. | | .. versionadded:: 0.24.0 | | __bytes__(self) -> bytes | Return bytes representation of the Series. | | .. versionadded:: 0.24.0 | | __constructor__(self, *args, **kwargs) -> 'Series' | Constructor used when subclassing NDFrame. | | __init__(self, data=None, index=None, dtype=None, name=None, copy=False, fastpath=False) | One-dimensional ndarray with axis labels (including time series). | | Labels need not be unique but must be a hashable type. The object supports | both integer- and label-based indexing and provides a host of methods for | performing operations involving the index. Statistical methods from | ndarray have been overridden to automatically exclude missing data (currently | represented as NaN). | | Parameters | ---------- ... ``` 可以看到,打印出了 Series 的构造函数以及其它方法和属性的说明。 2. 使用 `?` 符号: ```python import pandas as pd # 创建一个 Pandas Series s = pd.Series([1, 2, 3]) # 使用 ? 符号查看 Series 的参数 s? ``` 运行结果: ``` Type: pandas.core.series.Series String form: 0 1 1 2 2 3 dtype: int64 Length: 3 Docstring: One-dimensional ndarray with axis labels (including time series). Labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Statistical methods from ndarray have been overridden to automatically exclude missing data (currently represented as NaN). ``` 可以看到,打印出了 Series 的数据类型、字符串形式、长度和文档字符串。 ### 回答2: 要查看Pandas Series的参数,可以使用`.describe()`和`.info()`这两个函数。 `.describe()`函数提供了有关Series的统计描述信息,包括计数、均值、标准差、最小值、25%分位数、中位数、75%分位数和最大值。这些统计数据可以帮助我们了解Series的基本特征。 另一个函数`.info()`提供了有关Series的基本信息,包括索引类型、数据类型和非空值的数量。这个函数还可以告诉你Series占用的内存空间。 例如,假设我们有一个名为`my_series`的Series,我们可以使用以下方式检查其参数: ```python import pandas as pd # 创建一个Series my_series = pd.Series([10, 20, 30, 40, 50]) # 使用.describe()函数查看参数 print(my_series.describe()) # 使用.info()函数查看参数 my_series.info() ``` 运行上述代码,我们会得到以下输出: ``` count 5.0 mean 30.0 std 15.8 min 10.0 25% 20.0 50% 30.0 75% 40.0 max 50.0 dtype: float64 <class 'pandas.core.series.Series'> RangeIndex: 5 entries, 0 to 4 Data columns (total 1 columns): 0 5 non-null int64 dtypes: int64(1) memory usage: 168.0 bytes ``` 从输出结果可以看出,Series中包含5个非空值,所有值的均值为30.0,标准差为15.8。此外,数据类型为int64,占用的内存空间为168.0字节。 ### 回答3: 要查看Pandas Series的参数,可以使用Python中的内置函数type()和dir()。首先,使用type()函数检查Series的类型。例如,假设我们有一个名为s的Series对象,可以使用type(s)来查看其类型。结果可能会显示"Serie"或类似的输出,以确认对象为Series类型。 接下来,使用dir()函数来查看Series对象的所有可用属性和方法。例如,可以使用dir(s)来查看Series对象s的所有属性和方法。该函数将返回一个包含对象所有属性和方法名称的列表。 另外,可以使用help()函数来获取关于Series对象的详细说明。例如,输入help(s)将会输出一个包含Series对象的详细文档字符串的帮助页面。 除了这些方法,还可以在Pandas官方文档中查找Series的参数和方法说明。Pandas官方文档提供了全面的文档,其中包含了Pandas库中的所有对象和功能的详细说明,包括Series对象的参数和方法。可以在网上搜索"Pandas官方文档"并浏览相关页面来查找有关Series对象的参数信息。 综上所述,要查找Pandas Series对象的参数,可以使用type()函数确认其类型,使用dir()函数查看其所有属性和方法,使用help()函数获取详细的说明,或者查看Pandas官方文档获取更全面的参数信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值