私信  •  关注

SpghttCd

SpghttCd 最近创建的主题
SpghttCd 最近回复了
6 年前
回复了 SpghttCd 创建的主题 » 我正在尝试用python对csv进行排序/拆分

我想最方便的方法是用熊猫 groupby ,因为它同时提供了唯一的id及其相应的子数据帧:

import pandas as pd

df = pd.read_csv('Data.csv')

for id, group in df.groupby('device_id'):
      group.to_csv(f'{id}.csv')
6 年前
回复了 SpghttCd 创建的主题 » 用python中的科学记数法绘制表?

你可以试试 df.style.format() 正如 docs .

要在科学记数法中格式化df的最后三列,请使用:

with open('test.html', 'w') as f:
    f.write(df.style.format({col: '{:.2e}' for col in df.columns[-3:]}).render())

结果图片:

enter image description here