【发布时间】:2017-09-09 13:50:21
【问题描述】:
我正在为我的工作处理一些 csv。下面的代码有效,它只有一个小问题。它在“df.insert(0,'ID',' ')”行前面添加一列,列名为空白,并且正在计算行数。发生这种情况有什么原因吗?请随时提供任何见解或挑选我所拥有的东西,因为我是 Python 新手,我相信这可以清理或更有效地运行。
谢谢,
import pandas as pd
# Enter the full file path you want manipulated here
print('Enter Filename Path')
file = input()
# Enter the report category you want added here. This needs to be exact
print('Report Category')
rcat = input()
# Reads the CSV given above
df = pd.read_csv(file)
# This inserts the columns needed to fit the new VulnMan DB
df.insert(0, 'ID', ' ')
df.insert(4, 'Report Category', (rcat))
df.insert(5, 'Status', 'Not Started ')
df.insert(6, 'Comments', ' ')
# Saves the file in the SAME NAME
df.to_csv(file)
【问题讨论】:
-
这看起来像是重复感谢您的提醒,并对重复的问题感到抱歉。
标签: python python-3.x pandas