简体   繁体   English

如何将今天的日期放在 Python 数据框中每一行的第一列?

[英]How do I put today's date in the first column of every row in Python's dataframe?

I use the following code to move data from one Excel file to another:我使用以下代码将数据从一个 Excel 文件移动到另一个:

import pandas as pd
inventory=pd.read_excel('Original_File.xlsx', skiprows=3)
inventory.to_excel('New_File.xlsx', index=False)

How do I place today's date in the first column of every row that contains data in New_File.xlsx?如何将今天的日期放在包含 New_File.xlsx 数据的每一行的第一列中?

Like this:像这样:

import pandas as pd
from datetime import datetime
inventory=pd.read_excel('Original_File.xlsx', skiprows=3)
inventory.insert(0, 'today_date', datetime.today().strftime('%Y-%m-%d'))
inventory.to_excel('New_File.xlsx', index=False)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何通过年龄和今天计算出生年份? - how do i calculate the year of birth by it's age and date of today? 如何使用 python 在文件中搜索包含今天日期的字符串? - How do I search for a string containing today's date/dates in a file using python? 如何从今天的日期中减去指定的日期 - How can I subtract the specified date from today's date 如何检查熊猫数据框中的日期时间列是否属于每一行的相同日期? - How do you check if the datetime column in a pandas dataframe belong to the same date for every row? 如何用输入日期减去今天的日期? - How to subtract today's date with an input date? 在Python中搜索文件以获取今天的日期 - Search a File for Today's Date in Python 如何在“python”中将“约35分钟20秒前”和“9.35 AM 4月2日”分别更改为今天的日期和02-04-2019? - How do I change “about 35 mins 20 sec ago” and “9.35 AM Apr 2nd” to today's date and 02-04-2019 respectively in python? 在 Pandas 中,如何找到一列中每个键的每第三行并添加带有第三行信息的新列? - In Pandas, how do I find every 3rd row for each key in one column and add a new column with the 3rd row's info? 如何转换包含 1 和 0 的数据帧并将新列添加到表示 Python 中整行的十六进制值的同一数据帧 - how to convert a dataframe containing 1's and 0's and add a new column to the same dataframe that represents the hex value of entire row in python 如何在Python中快速计算数据框列中每个值的概率? - How do I calculate the probability of every value in a dataframe column quickly in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM