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

如何实现表格底部添加D/T、S/T百分比行的需求?

How to Add D/T and S/T Percentage Rows to Your Table

Absolutely, this request is completely achievable! Whether you're calculating manually, using a spreadsheet tool, or writing a quick script, you can generate those percentage rows easily. Here's how to go about it:

Manual Calculation Approach

For each column, divide the value from the D row by the corresponding value in the T row, and repeat the same for the S row divided by T. Round the results to three decimal places (matching your desired output):

  • Column a: D/T = 2168 / 13208 ≈ 0.164; S/T = 435 / 13208 ≈ 0.033
  • Column b: D/T = 1545 / 5438 ≈ 0.284; S/T = 212 / 5438 ≈ 0.040
  • Column c: D/T = 2163 / 12935 ≈ 0.167; S/T = 410 / 12935 ≈ 0.032
  • Column d: D/T = 1540 / 5337 ≈ 0.288; S/T = 193 / 5337 ≈ 0.036 (note: your desired output shows 0.04, which is a rounding to two decimal places—adjust based on your preference)
  • Column e: D/T = 2153 / 12656 ≈ 0.170; S/T = 391 / 12656 ≈ 0.031

Spreadsheet Tool (Excel/Google Sheets)

If you're using a spreadsheet tool, this is straightforward:

  1. In cell A5, type D/T; in cell A6, type S/T
  2. In cell B5, enter the formula =B2/B4 (assuming D is in row 2, T is in row 4)
  3. Drag the fill handle from B5 to F5 to apply the formula across all columns
  4. Repeat for cell B6 with =B3/B4, then drag to F6
  5. Format the cells to show 3 decimal places (adjust to 2 if you want values like 0.04 instead of 0.036)

Python Script (Using Pandas)

If you prefer using code to automate this, here's a quick pandas snippet:

import pandas as pd

# Create the original table data
data = {
    'SD': ['D', 'S', 'T'],
    'a': [2168, 435, 13208],
    'b': [1545, 212, 5438],
    'c': [2163, 410, 12935],
    'd': [1540, 193, 5337],
    'e': [2153, 391, 12656]
}

df = pd.DataFrame(data).set_index('SD')

# Calculate the percentage rows
df.loc['D/T'] = df.loc['D'] / df.loc['T']
df.loc['S/T'] = df.loc['S'] / df.loc['T']

# Round to 3 decimal places (change to 2 if needed)
df = df.round(3)

# Print the final table
print(df.reset_index().to_string(index=False))

Final Formatted Table (Matching Your Desired Output)

SDabcde
D21681545216315402153
S435212410193391
T13208543812935533712656
D/T0.1640.2840.1670.2880.170
S/T0.0330.0400.0320.0360.031

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 06:23:17