csv

Python - Select different row values from csv and combine them in new csv

回眸只為那壹抹淺笑 提交于 2020-03-26 04:04:08
问题 I have a csv file containing hourly data of wave conditions and data from measurements taken during certain times. I want to select wave conditions 6 hours before the measurement and the outcomes of the measurements. I want to export that to a new csv file for all the measurements. The code below selects the right rows for 1 measurement: df = pd.read_csv(csv, header=None, names=['survey', 'time', 'tides', 'mwp', 'swh', 'mwd', 'data1', 'data2', 'data3', 'data4', 'data5']) xp = [datetime

Python - Select different row values from csv and combine them in new csv

烈酒焚心 提交于 2020-03-26 04:04:08
问题 I have a csv file containing hourly data of wave conditions and data from measurements taken during certain times. I want to select wave conditions 6 hours before the measurement and the outcomes of the measurements. I want to export that to a new csv file for all the measurements. The code below selects the right rows for 1 measurement: df = pd.read_csv(csv, header=None, names=['survey', 'time', 'tides', 'mwp', 'swh', 'mwd', 'data1', 'data2', 'data3', 'data4', 'data5']) xp = [datetime

javacsv生成的csv用excel打开中文乱码

女生的网名这么多〃 提交于 2020-03-25 21:05:43
在 SourceForge 上找到读写csv文件的开源代码。 但是生成的csv文件,如果用excel打开时,中文全部会乱码。原因是excel在解析csv文件时,默认以utf-8带BOM格式去解析的。 utf-8保存的csv格式文件要让Excel正常打开的话,必须加入在文件最前面加入BOM(Byte order)。 主要 修改代码 如下: private void checkInit() throws IOException { if (!initialized) { if (fileName != null) { outputStream = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(fileName), charset)); //为了要让EXCEL显示csv中的中文不乱码,手动的给将要输出的内容加上BOM标识 if (isUtf8WithBOM) { outputStream.write(new String(new byte[]{(byte) 0xEF, (byte) 0xBB, (byte) 0xBF})); } } initialized = true; } } 完整代码 放到了gitee上。 来源: https://www.cnblogs.com/lee2guang/p/12569248

How to split one csv into multiple files in python

╄→尐↘猪︶ㄣ 提交于 2020-03-25 17:50:31
问题 I have a csv file (world.csv) looks like this : "city","city_alt","lat","lng","country" "Mjekić","42.6781","20.9728","Kosovo" "Mjekiff","42.6781","20.9728","Kosovo" "paris","42.6781","10.9728","France" "Bordeau","16.6781","52.9728","France" "Menes","02.6781","50.9728","Morocco" "Fess","6.6781","3.9728","Morocco" "Tanger","8.6781","5.9728","Morocco" And i want to split it to multiple file by country like this: Kosovo.csv : "city","city_alt","lat","lng","country" "Mjekić","42.6781","20.9728",

go 读写csv文件

偶尔善良 提交于 2020-03-25 17:04:47
package main import ( "encoding/csv" "fmt" "os" ) func write() { f, err := os.Create("test.csv") if err != nil{ fmt.Println(err) return } defer f.Close() var data = make([][]string, 4) data[0] = []string{"标题", "作者", "时间"} data[1] = []string{"羊皮卷", "鲁迅", "2008"} data[2] = []string{"易筋经", "唐生", "665"} f.WriteString("\xEF\xBB\xBF") // 写入一个UTF-8 BOM w := csv.NewWriter(f) //创建一个新的写入文件流 w.WriteAll(data) w.Flush() } func Read() { f, err := os.Open("test.csv") if err != nil{ fmt.Println(err) return } defer f.Close() w := csv.NewReader(f) data, err := w.ReadAll() if err != nil{ fmt.Println(err) return

Process an array and group rows by one field from a csv

一笑奈何 提交于 2020-03-24 14:20:08
问题 Edit for clarity after reading several comments and answers Consider the below CSV Column1,Column2,Column3 John,Doe,Developer Joey,Doe,Manager Joe,Doe,Developer I need to be able to read the CSV in perl to be able to render the following: ---- My list ---- -> Person 1 -> Name: John Doe -> Role: Developer -> Person 2 -> Name: Joey Doe -> Role: Manager -> Person 3 -> Name: Joe Doe -> Role: Developer --- Groups --- -> Developer -> Members: John Doe, Joe Doe -> Manager -> Members: Joey Doe ---

Spring-Batch将CSV文件转为XML文件

十年热恋 提交于 2020-03-24 04:59:52
1 介绍 用Spring Batch实现一个简单的需求,将csv文件转换成xml文件。 csv文件如下:record.csv username, user_id, transaction_date, transaction_amount devendra, 1234, 31/10/2015, 10000 john, 2134, 3/12/2015, 12321 robin, 2134, 2/02/2015, 23411 转换成的xml文件如下:record.xml <?xml version="1.0" encoding="UTF-8"?><transactionRecord> <transactionRecord> <amount>10000.0</amount> <transactionDate>2015-10-31T00:00:00+08:00</transactionDate> <userId>1234</userId> <username>devendra</username> </transactionRecord> <transactionRecord> <amount>12321.0</amount> <transactionDate>2015-12-03T00:00:00+08:00</transactionDate> <userId>2134</userId>

【项目2】将csv文件转为xlsx

删除回忆录丶 提交于 2020-03-24 04:57:58
以后再追加注释 #! python3 ''' Author: i_orange 将csv转为xlsx的小程序 ''' import csv, openpyxl, os, time def convert(): pass print('%%请将要转换的csv文件放置到空文件夹下%%') path = input('请输入csv文件所在文件夹路径:') pathList = path.split(os.sep) newPath = (os.sep).join(pathList) #0.切换到工作目录 os.chdir(newPath) #1.程序计时 start = time.clock() data = time.strftime('%Y%m%d%H%M%S') #2. 计数 count = 1 #2.创建处理后的保存目录 newDir = ['转换后',data] pathList.extend(newDir) newPath1 = (os.sep).join(pathList) os.makedirs(newPath1,exist_ok = True) #3.列出工作目录下的文件 for folderName, subFolderNames, fileNames in os.walk(newPath): ## print('当前所在文件夹名称:'+ folderName)

Bash How to wrap values of the first line of a csv file with quotations, if they do not exist

穿精又带淫゛_ 提交于 2020-03-23 06:38:31
问题 The other day I asked how to wrap values of the first line of a csv file with quotations. I was given this reply which worked great. $ cat file.csv word1,word2,word3,word4,word5 12345,12346,12347,12348,12349 To put quotes around the items in the first line only: $ sed '1 { s/^/"/; s/,/","/g; s/$/"/ }' file.csv "word1","word2","word3","word4","word5" 12345,12346,12347,12348,12349 I now need to test if the quotes exist around the values to eliminate chances of double quoting values. 回答1: This

Bash How to wrap values of the first line of a csv file with quotations, if they do not exist

拥有回忆 提交于 2020-03-23 06:37:03
问题 The other day I asked how to wrap values of the first line of a csv file with quotations. I was given this reply which worked great. $ cat file.csv word1,word2,word3,word4,word5 12345,12346,12347,12348,12349 To put quotes around the items in the first line only: $ sed '1 { s/^/"/; s/,/","/g; s/$/"/ }' file.csv "word1","word2","word3","word4","word5" 12345,12346,12347,12348,12349 I now need to test if the quotes exist around the values to eliminate chances of double quoting values. 回答1: This