df.unique()

时间: 2024-05-05 11:17:20 浏览: 11
As an AI language model, I don't have access to any specific dataframe. However, I can provide a general explanation of what the method `df.unique()` does. `df.unique()` is a method that can be used on a pandas dataframe `df`. It returns an array of unique values in the dataframe column(s). It can be used to identify the unique values in a dataframe column or multiple columns. For example, if we have a dataframe with a column called "fruit" and we want to know the unique values in that column, we can use the following code: ``` import pandas as pd df = pd.DataFrame({'fruit': ['apple', 'banana', 'apple', 'orange', 'banana']}) unique_fruits = df['fruit'].unique() print(unique_fruits) ``` Output: ``` ['apple' 'banana' 'orange'] ``` This code will return an array of unique values in the "fruit" column of the `df` dataframe, which are 'apple', 'banana', and 'orange'.

相关推荐

import tushare as ts import datetime # 设置 token,用于认证 ts.set_token('530fbc2b682d65696dbeec010a893f70d6953fbb6842151003c3e12f') # 初始化 tushare pro = ts.pro_api() df = pro.daily(fields = 'ts_code,trade_date,open,close',start_date='20180701', end_date='20180718') def get_stock_poll(df): stock_pool=[] for code in df['ts_code'].unique(): temp_df = df[df['ts_code'] == code ] for i in range(len(temp_df)-3): if (temp_df.iloc[i + 3]['close'] > temp_df.iloc[i + 2]['close']) and \ (temp_df.iloc[i + 2]['close'] > temp_df.iloc[i + 2]['open']) and \ (temp_df.iloc[i + 1]['close'] > temp_df.iloc[i + 1]['open']) and \ (temp_df.iloc[i]['close'] > temp_df.iloc[i]['open'])and \ (temp_df.iloc[i + 3]['close'] > temp_df.iloc[i + 2]['close'])and \ (temp_df.iloc[i + 2]['close'] > temp_df.iloc[i + 1]['close']) and\ (temp_df.iloc[i + 1]['close'] > temp_df.iloc[i]['close']): stock_pool.append(code) break return stock_pool def buy_stock(stock_pool,df): buy_list = [] for code in stock_pool: temp_df = df[df['ts_code']==code] for i in range(len(temp_df-2)): if(temp_df.iloc[i + 2]['close'] < temp_df.iloc[i + 2]['open']) and \ (temp_df.iloc[i + 1]['close'] < temp_df.iloc[i + 1]['open']) and \ (temp_df.iloc[i]['close'] < temp_df.iloc[i]['open'])and \ (temp_df.iloc[i + 2]['close'] < temp_df.iloc[i + 1]['close'])and \ (temp_df.iloc[i + 1]['close'] < temp_df.iloc[i]['close']): buy_list.append(code) break return buy_list def sell_stock(buy_stock,df): sell_list = [] for stock in buy_list: buy_date=dateime.datetime.strptime(stock[1],"%Y-%m-%d") current_date = datetime.datetime.today() days_held = (current_date - buy_date).days if days_held >=3: sell_list.append(stock[0]) print("sell list:",sell_list)要求上述代码在聚宽上运行

优化代码 def cluster_format(self, start_time, end_time, save_on=True, data_clean=False, data_name=None): """ local format function is to format data from beihang. :param start_time: :param end_time: :return: """ # 户用簇级数据清洗 if data_clean: unused_index_col = [i for i in self.df.columns if 'Unnamed' in i] self.df.drop(columns=unused_index_col, inplace=True) self.df.drop_duplicates(inplace=True, ignore_index=True) self.df.reset_index(drop=True, inplace=True) dupli_header_lines = np.where(self.df['sendtime'] == 'sendtime')[0] self.df.drop(index=dupli_header_lines, inplace=True) self.df = self.df.apply(pd.to_numeric, errors='ignore') self.df['sendtime'] = pd.to_datetime(self.df['sendtime']) self.df.sort_values(by='sendtime', inplace=True, ignore_index=True) self.df.to_csv(data_name, index=False) # 调用基本格式化处理 self.df = super().format(start_time, end_time) module_number_register = np.unique(self.df['bat_module_num']) # if registered m_num is 0 and not changed, there is no module data if not np.any(module_number_register): logger.logger.warning("No module data!") sys.exit() if 'bat_module_voltage_00' in self.df.columns: volt_ref = 'bat_module_voltage_00' elif 'bat_module_voltage_01' in self.df.columns: volt_ref = 'bat_module_voltage_01' elif 'bat_module_voltage_02' in self.df.columns: volt_ref = 'bat_module_voltage_02' else: logger.logger.warning("No module data!") sys.exit() self.df.dropna(axis=0, subset=[volt_ref], inplace=True) self.df.reset_index(drop=True, inplace=True) self.headers = list(self.df.columns) # time duration of a cluster self.length = len(self.df) if self.length == 0: logger.logger.warning("After cluster data clean, no effective data!") raise ValueError("No effective data after cluster data clean.") self.cluster_stats(save_on) for m in range(self.mod_num): print(self.clusterid, self.mod_num) self.module_list.append(np.unique(self.df[f'bat_module_sn_{str(m).zfill(2)}'].dropna())[0])

最新推荐

recommend-type

H11111111111111111111111111111111111111111111111111111

sadfasfdgsdgsdfgsdgsdg
recommend-type

16路舵机机械臂.zip16路舵机机械臂_.zip

16路舵机机械臂.zip16路舵机机械臂_
recommend-type

Python_来自微软的熟悉的、友好的、现代的表情符号集合.zip

Python_来自微软的熟悉的、友好的、现代的表情符号集合
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MySQL数据库性能提升秘籍:揭秘性能下降幕后真凶及解决策略

![MySQL数据库性能提升秘籍:揭秘性能下降幕后真凶及解决策略](http://xiaoyuge.work/explain-sql/index/2.png) # 1. MySQL数据库性能优化概述** MySQL数据库性能优化是一项至关重要的任务,可以显著提高应用程序的响应时间和整体用户体验。优化涉及识别和解决影响数据库性能的因素,包括硬件资源瓶颈、软件配置不当和数据库设计缺陷。通过采取适当的优化策略,可以显著提升数据库性能,满足业务需求并提高用户满意度。 # 2. MySQL数据库性能下降的幕后真凶 ### 2.1 硬件资源瓶颈 #### 2.1.1 CPU利用率过高 **症状:
recommend-type

如何在unity创建按钮

在 Unity 中创建按钮的步骤如下: 1. 在 Unity 中创建一个 UI Canvas,选择 GameObject -> UI -> Canvas。 2. 在 Canvas 中创建一个按钮,选择 GameObject -> UI -> Button。 3. 在场景视图中调整按钮的位置和大小。 4. 在 Inspector 中设置按钮的文本、颜色、字体等属性。 5. 添加按钮的响应事件,选择按钮,在 Inspector 的 On Click () 中添加相应的方法。 这样就可以创建一个按钮了,你可以在游戏中使用它来触发相应的操作。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

表锁问题全解析,深度解读MySQL表锁问题及解决方案

![表锁问题全解析,深度解读MySQL表锁问题及解决方案](https://img-blog.csdnimg.cn/img_convert/a89711a10f6b856a777a9eed389c5112.png) # 1. 表锁基础** 表锁是一种数据库并发控制机制,用于防止多个事务同时访问和修改同一行或表中的数据,从而保证数据的完整性和一致性。表锁通过对表或表中的特定行施加锁来实现,以确保在事务完成之前,其他事务不能对这些数据进行修改。 表锁分为两种主要类型:共享锁(S锁)和排他锁(X锁)。共享锁允许多个事务同时读取同一行或表中的数据,但不能修改。排他锁则允许一个事务独占地访问和修改同