我想最方便的方法是用熊猫 groupby ,因为它同时提供了唯一的id及其相应的子数据帧:
groupby
import pandas as pd df = pd.read_csv('Data.csv') for id, group in df.groupby('device_id'): group.to_csv(f'{id}.csv')
你可以试试 df.style.format() 正如 docs .
df.style.format()
要在科学记数法中格式化df的最后三列,请使用:
with open('test.html', 'w') as f: f.write(df.style.format({col: '{:.2e}' for col in df.columns[-3:]}).render())
结果图片: