You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何无需硬编码提取10000×8的DataFrame第8列的唯一字符串

获取DataFrame指定列的唯一字符串列表
  • 先导入pandas并读取目标CSV文件:
    import pandas as pd
    
    # 读取CSV文件到DataFrame
    df = pd.read_csv('你的文件路径.csv')
    
  • 针对第8列处理(注意:pandas默认列索引从0开始,所以第8列对应索引为7;如果知道列名,也可直接用列名):
    • 按列位置提取唯一值并转成列表:
      # 获取第8列(索引7)的唯一字符串列表
      unique_strings = df.iloc[:, 7].unique().tolist()
      
    • 若已知第8列的列名(比如列名为target_col),可直接用列名操作:
      # 替换为实际列名即可
      unique_strings = df['target_col'].unique().tolist()
      
  • 查看结果:
    print(unique_strings)
    

内容的提问来源于stack exchange,提问作者PKrange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 03:25:21