def f(x): return pd.Series([x.min(), x.max(), x.mean(), x.max()-x.min()], index = ['最小值', '最大值', '平均值', '极差']) frame.apply(f) 4.5 排序 排序时对数据集的重要操作,有时候我们把数据输出到excel并要求排序,我们就需要用到该操作。 Series对象用sort_index排序;而...
nopython=True, cache=True) def custom_mean_jitted(x): return (x * x).mean() In [4]: %time out = rolling_df.apply(custom_mean, raw=True) CPU times: user 3.57 s, sys: 43.8 ms, total: 3.61 s Wall time: 3.57 s
Call re.findall on each element, returning DataFrame with one row for each match and one column for each regex capture group len() Compute string lengths strip() Equivalent to str.strip rstrip() Equivalent to str.rstrip lstrip() Equivalent to str.lstrip partition() Equivalent to str.partition...
File "E:\PycharmScripts\pandas_Scripts\venv\lib\site-packages\pandas\core\series.py", line 942, in __getitem__ return self._get_value(key) File "E:\PycharmScripts\pandas_Scripts\venv\lib\site-packages\pandas\core\series.py", line 1051, in _get_value loc = self.index.get_loc(label)...
df[df[column_name].duplicated()] # 查看column_name字段数据重复的数据信息 4.数据选取 常用的数据选取的10个用法: df[col] # 选择某一列 df[[col1,col2]] # 选择多列 s.iloc[0] # 通过位置选取数据 s.loc['index_one'] # 按索引选取数据 df.iloc[0,:] # 返回第 df.iloc[0,0] # 返回第...
这是一个常见的数据清洗任务,确保数据的一致性和准确性。# 运行以下代码deffix_century(x): year = x.year - 100if x.year > 1989else x.yearreturn datetime.date(year, x.month, x.day)# apply the function fix_century on the column and replace the values to the right onesdata['Yr_Mo_D...
df1.insert(loc = 1, # 插入位置,插入为列索引为1的位置 column='C++', # 插入一列,这一列名字 value = np.random.randint(0,151,size = 10)) # 插入的值 insert只能插入列,不能插入行,插入行用append dfn = pd.DataFrame(np.random.randint(0,151,size = (1,4)),columns=['Python','C++',...
df[[columnname]]:标示一个DataFrame DataFrame可以用join函数进行拼接,而Series则不行 六。df拼接:join df.join(other, on=None, how='left', lsuffix='', rsuffix='', sort=False) 将df 和other按列合并, on:None代表是按照索引index进行匹配合并 columnsname:按照列进行合并,other列表需要将columnsname设...
df['column'] =df['column'].astype('int32') # 将64位数据类型降为32位 实践练习(可选) 验证合并质量:检查现有项目中的数据合并逻辑,应用validate='one_to_one'进行验证。 交叉连接实践:尝试合并产品与地区数据表,并通过逻辑筛选获取有价值的组合。
median() Return the median of the values in the specified axis melt() Reshape the DataFrame from a wide table to a long table memory_usage() Returns the memory usage of each column merge() Merge DataFrame objects min() Returns the min of the values in the specified axis mod() Modules ...