【问题标题】:Python3.6 - Divide All Column Values from .csv by Single Scalar (not using pandas and dataframes)Python3.6 - 将 .csv 中的所有列值除以单个标量(不使用熊猫和数据框)
【发布时间】:2025-11-29 23:40:01
【问题描述】:

我正在为 Windows 使用 python3.6 - 32 位。我想在绘制之前将第 0 列中的所有数据除以 3600。我该怎么做呢?请看下面的代码。 PS 代码可以正常工作,只是想从 sec 获取我的时间数据。到小时(因此是 3600 值)都在同一个程序中。

import matplotlib.pyplot as plt
import csv

x = []
y = []

with open('C:\Log_data5.dat','r') as csvfile:
    plots = csv.reader(csvfile, delimiter=',')
    for row in plots:
        x.append(float(row[0]))
        y.append(float(row[5]))


plt.plot(x,y, label='Loaded from file!')
plt.ylabel('Temperature(°C)')
plt.xlabel('Time(s)')
plt.title('Temp vs. Time')
plt.ticklabel_format(style='plain')
plt.ticklabel_format(useOffset=False)
plt.legend()
plt.show()

【问题讨论】:

  • 你可以把x.append(float(row[0]))改成x.append(float(row[0])/3600.0)

标签: python-3.x divide scalar


【解决方案1】:

我认为您可以将x.append(float(row[0])) 更改为x.append(float(row[0])/3600)

这会将您的row[0](即时间)值除以 3600,然后再将它们插入您的 x 轴列表。

不要忘记将您的 x 轴标签单元从 s 更新为 hr

【讨论】:

    最近更新 更多