csv

Reading .csv through DictReader

偶尔善良 提交于 2021-01-27 21:19:55
问题 I'm just trying to read a .csv using the first row as keys for the dictionary, with no success. My file has two lines (test), items being delimited by tabs. subjectID logID logTimestamp gameKey userID writer gameTime gameCode gameDesc 9991 1711774 6/13/14 E9E91B56 L11-13 general 358 1002 GAMESCRIBE_CREATED Code : def process_data(file_path): users = {} # Open the .csv file and creates a dict of actions with open(file_path, 'rb') as csvfile: spamreader = csv.DictReader(csvfile, delimiter='\t')

Find maximum value of each day from hourly data

≯℡__Kan透↙ 提交于 2021-01-27 21:12:10
问题 I have problem getting max value of each day from hourly data. Original file contain 24 data for each name each day(there are too many name). as example here is 24 data for one name: Start Time Period name value 2/23/2019 0:00 60 MBTS_H2145X 100 2/23/2019 1:00 60 MBTS_H2145X 100 2/23/2019 2:00 60 MBTS_H2145X 1 2/23/2019 3:00 60 MBTS_H2145X 1 2/23/2019 4:00 60 MBTS_H2145X 1 2/23/2019 5:00 60 MBTS_H2145X 2324 2/23/2019 6:00 60 MBTS_H2145X 2323 2/23/2019 7:00 60 MBTS_H2145X 2323 2/23/2019 8:00

secure-file-priv Empty set

强颜欢笑 提交于 2021-01-27 20:14:49
问题 Windows 2007 MySQL 5.7 Receiving error : ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement So I assumed that it was simply a privilege error for the directory that I had stored my DB. So I ran: SHOW VARIABLES LIKE "secure-file-priv"; and returned: Empty set (0.00 sec) so I searched for "my.ini" my.ini is located in C:\ProgramData\MySQL\MySQL Server 5.7 MySQL is installed in C:\Program Files (x86) I made a copy of my Links

2D list to csv - by column

廉价感情. 提交于 2021-01-27 20:00:10
问题 I'd like to export the content of a 2D-list into a csv file. The size of the sublists can be different. For example, the 2D-list can be something like : a = [ ['a','b','c','d'], ['e','f'], ['g'], [], ['h','i'] ] I want my csv to store the data like this - "by column" : a,e,g, ,h b,f, , ,i c d Do I have to add some blank spaces to get the same size for each sublist ? Or is there another way to do so ? Thank you for your help 回答1: You can use itertools.zip_longest : import itertools, csv a = [

Why is TextIOWrapper closing the given BytesIO stream?

谁说我不能喝 提交于 2021-01-27 19:40:21
问题 If I run following code in python 3 from io import BytesIO import csv from io import TextIOWrapper def fill_into_stringio(input_io): writer = csv.DictWriter(TextIOWrapper(input_io, encoding='utf-8'),fieldnames=['ids']) for i in range(100): writer.writerow({'ids': str(i)}) with BytesIO() as input_i: fill_into_stringio(input_i) input_i.seek(0) I get an error: ValueError: I/O operation on closed file. While if I don't use the TextIOWrapper the io stream stays open. As an example if I modify my

Names of columns change from CSV to R: dot instead of slash

狂风中的少年 提交于 2021-01-27 19:30:50
问题 When I inport a CSV file in R the names of the columns change. They go from "Fe/Cu" to "Fe.Cu". But I have this mysterious problem only with one CSV file. I tried to rename the columns colnames(a[12:ncol(a)])=c("Fe/Cu","Fe/Zn","Fe/Ba") But nothing happens. Any ideas? 回答1: Adding check.names=FALSE to csv.read function call will allow you to get the original names. This is because by default csv.read will check if column names are syntactically valid as stated by @Asayat in the commets. From

fopen - failed to open stream: Permission denied

天涯浪子 提交于 2021-01-27 19:26:49
问题 Is it possible to write data to CSV while the file is opened from desktop? Because I am trying to write some input data to CSV when user submit the form, but I am getting above error when the file is opened from my desktop. My system will only write to csv when I close the file. Error when meeting the line $fp = fopen("C:\Users\lenovo\Desktop\sample.csv", "w"); 回答1: Change the permission of the file sample.csv by using the following command on the terminal in the folder where the file is-

nmap and print(nm.csv()) help needed to print out to csv.file

陌路散爱 提交于 2021-01-27 19:25:40
问题 I need you help with nmap script and printing the output to csv file. When I run the script and finish it with print(nm.csv()) I got the following results displayed which is what I want first place: host;hostname;hostname_type;protocol;port;name;state;product;extrainfo;reason;version;conf;cpe 82.214.228.176;176.228.214.82.in-addr.arpa;PTR;tcp;21;ftp;open;;;syn-ack;;3; 82.214.228.176;176.228.214.82.in-addr.arpa;PTR;tcp;22;ssh;open;;;syn-ack;;3; 82.214.228.176;176.228.214.82.in-addr.arpa;PTR

Write Nested Dictionary to CSV

て烟熏妆下的殇ゞ 提交于 2021-01-27 18:45:31
问题 I am trying to write a nested dictionary to CSV in Python. I looked at the csv.DictWriter documentation on python.org and some of the examples here on stackoverflow but I can't figure out the last part. Here is a representative data set: data = {u'feeds': [{u'feed_code': u'free', u'feed_name': u'Free'}, {u'feed_code': u'paid', u'feed_name': u'Paid'}, {u'feed_code': u'grossing', u'feed_name': u'Grossing'}], u'code': 200} ColTitle = ['code','feed_code','feed_name'] with open('test.csv','wb') as

How to write a pandas.DataFrame to csv file with custom header?

耗尽温柔 提交于 2021-01-27 17:24:14
问题 I have a dataframe import pandas as pd df = pd.DataFrame([[1, 2], [3, 4]], columns=['a', 'b']) I want to write df to a csv file but not using the columns ['a', 'b'] . The first line is my custom string and the rest are the content of df.values . For example: numrows numcols note 1 2 3 4 Can I do this with pandas or I have to manually loop through the content and write to file? 回答1: You can first create a csv file with the custom text in the first line, and then append the dataframe to it.