且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

循环遍历目录中的文件,在pandas中添加日期列

更新时间:2023-09-17 16:15:34

这似乎是一个合理的方法.pd.concat 获取一个 pandas 对象列表并将它们连接起来.append 在您循环浏览文件时将每个 frame 添加到列表中.不过,我认为有两件事需要改变.

This seems like a reasonable way to do it. The pd.concat takes a list of pandas objects and concatenates them. append adds each frame to the list as you loop through the files. I see two things to change though.

  1. 您不需要frame = pd.DataFrame().当您将 dataframes 附加到列表时,它没有做任何事情.
  2. 我会将变量 list 的名称更改为其他名称.也许 frames 因为它是对内容的描述,并不意味着什么.
  1. You don't need frame = pd.DataFrame(). It is not doing anything as you are appending dataframes to the list.
  2. I'd change the name of the variable list to something else. Maybe frames as it is descriptive of the contents and doesn't already mean something.