【问题标题】:How to count specific column in excel csv file?如何计算excel csv文件中的特定列?
【发布时间】:2019-06-17 13:58:05
【问题描述】:

我有一个 csv 文件。它是 6 行 x 28 列。它有一个名为 OS_STATUS 的列。它在列中有两件事:活着或死去。我需要一个只能计算活人数量及其相应年龄(年龄是另一列)并绘制图表的代码。我需要一种只计算活人的方法。

import pandas as pd
import matplotlib as plt
import numpy as np

cereal = pd.read_csv('C:\\Users\\farid-PC\\Desktop\\class\\CS7265_BIG_DATA\\sam1.csv')
print(cereal)
x =[]
x.append(df['os_status'])

【问题讨论】:

  • 你有学过熊猫教程吗?该应用程序是如何工作的?出了什么问题?

标签: python pandas csv dataframe matplotlib


【解决方案1】:
df.loc[df['os_status'] == "live", "age"].value_counts().sort_index().plot(kind='bar')

【讨论】:

    【解决方案2】:

    我不是 pandas Excel 模块方面的专家,但这听起来很容易通过 xlwings 模块实现。您只需要遍历正在评估的任何行,然后您可以说if sheet.range('A{}'.format(row).value == 'Alive':

    `code to grab the name from same row`
    

    【讨论】:

      猜你喜欢
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多