小编bar*_*l3y的帖子

Python编辑CSV标头

我有一个名为temp的csv文件中的以下数据.

Item,Description,Base Price,Available
2000-000-000-300,AC - CF/M Series Green For Black Hood,299.99,3
2000-000-000-380,AC - CF/M Series Green For White Hood,299.99,3
Run Code Online (Sandbox Code Playgroud)

我需要更改标题才能阅读

Item Number,Item Description,List Price,QTY Available
Run Code Online (Sandbox Code Playgroud)

我一直在这里搜索类似的问题,并且没有我能理解的解决方案,因为我对python编程比较陌生.到目前为止,我有:

import csv
import os

inputFileName = "temp.csv"
outputFileName = os.path.splitext(inputFileName)[0] + "_modified.csv"

with open(inputFileName) as inFile, open(outputFileName, "w") as outfile:
    r = csv.reader(inFile)
    w = csv.writer(outfile)
Run Code Online (Sandbox Code Playgroud)

我知道只读取原始文件,然后写入_modified.如何选择当前标题然后更改它们以便它们写入新文件?

python

7
推荐指数
1
解决办法
2万
查看次数

VB转C#转换DateAndTime等价

我正在尝试将此VB块转换为C#.

  Public Function AddWorkingDays(ByVal DateIn As DateTime, _
   ByVal ShiftDate As Integer) As DateTime
    Dim b As Integer

    Dim datDate As DateTime = DateIn ' Adds the [ShiftDate] number of working days to DateIn'
    For b = 1 To ShiftDate
        datDate = datDate.AddDays(1)
        ' Loop around until we get the need non-weekend day'
        If Weekday(datDate) = 7 Then
            datDate = datDate.AddDays(2)
        End If
    Next
    Return datDate
End Function
Run Code Online (Sandbox Code Playgroud)

到目前为止我已经有了

public DateTime AddWorkingDays(DateTime DateIn, int ShiftDate)
{
    int b = 0; …
Run Code Online (Sandbox Code Playgroud)

.net c# vb.net

3
推荐指数
2
解决办法
649
查看次数

Python:将数据添加到第一个CSV列

使用Python v2.7.4:

我有以下CSV文件:

Item Number,Item Description,List Price,QTY Available
2000-000-000-380,AC - CF/M Series Green For White Hood,299.99,3
2000-000-000-400,AC - CF/M Series Orange For Black Hood,299.99,3
2000-000-000-480,AC - CF/M Series Orange For White Hood,299.99,3
Run Code Online (Sandbox Code Playgroud)

我一直在尝试将文件更改为:

Fulfillment,SKU,Qty
US,2000-000-300,3
US,2000-000-380,3
US,2000-000-400,3
Run Code Online (Sandbox Code Playgroud)

到目前为止,我有以下代码:

import csv
import os

inputFileName = "temp_modified.csv"
outputFileName = os.path.splitext(inputFileName)[0] + "_pro.csv"

with open(inputFileName, "rb") as inFile, open(outputFileName, "wb") as outfile:
    r = csv.reader(inFile)    
    w = csv.writer(outfile)

    r.next()    
    w.writerow(['Fulfillment', 'SKU', 'Qty'])

    for row in r:
        w.writerow((row[0], row[3]))
Run Code Online (Sandbox Code Playgroud)

使用此代码,我得到以下输出:

Fulfillment,SKU,Qty
2000-000-000-380,3
2000-000-000-400,3
2000-000-000-480,3 …
Run Code Online (Sandbox Code Playgroud)

python csv

2
推荐指数
1
解决办法
2065
查看次数

标签 统计

python ×2

.net ×1

c# ×1

csv ×1

vb.net ×1