gpt4 book ai didi

python - 在 Python/Pandas 中创建带有元数据头的 csv 文件,后跟时间序列

转载 作者:太空狗 更新时间:2023-10-30 01:34:08 24 4
gpt4 key购买 nike

我正在尝试创建一个 csv 文件,其中前几行包含元数据,然后是时间序列数据,因此它可以由另一个 Web 应用程序处理。我的 csv 文件应如下所示:

Code: ABC1

Frequency: Monthly

Description: Blah Blah

-------------------

2/1/1947 11.7

3/1/1947 11.9

我可以创建元数据的 csv 文件:

metadata=pd.Series([('code: ABC123'),('freqency: monthly'),('description: describecode'),('--------')])

metadata.to_csv("metadata.csv",index=False)

我可以创建时间序列的 csv

a=pd.Series((11.7,11.9),index=pd.date_range('1947-01-02','1947-01-03'))

a.to_csv("data.csv")

但我不知道如何将它们合并到顶部的格式中。

最佳答案

>>> with open('test.csv', 'w') as fout:
... fout.write('meta data\n:')
... meta_data.to_csv(fout)
... ts.to_csv(fout)

关于python - 在 Python/Pandas 中创建带有元数据头的 csv 文件,后跟时间序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24168507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com