csv

python第五次作业

情到浓时终转凉″ 提交于 2020-03-22 07:03:10
习题1:读入文件pmi_days.csv,完成以下操作: 1.统计质量等级对应的天数,例如: 优:5天 良:3天 中度污染:2天 2.找出PMI2.5的最大值和最小值,分 import csv import pandas as pd import numpy as np path = open(r"C:\Users\asus\pmi_days.csv") days_df = pd.read_csv(path) data = days_df.groupby('质量等级') you = dict([x for x in data])['优'] liang = dict([x for x in data])['良'] qingduwuran = dict([x for x in data])['轻度污染'] zhongduwuran = dict([x for x in data])['中度污染'] print("优:%d天" % len(you.index), "\n良:%d天" % len(liang.index), "\n轻度污染:%d天" % len(qingduwuran.index), "\n中度污染:%d天" % len(zhongduwuran.index)) sort_pm25 = days_df.sort_values(by='PM2.5') sort_pm25_2

How to parse this text file format into CSV format?

孤者浪人 提交于 2020-03-22 06:39:08
问题 I have a text file laid out as such where every field is a new line: id = 606149 Category Name = Structural Columns Family Name = Concrete-Square-Column Type Name = EXIST RH C1 16 x 16 Document = 15050 Peavy Struct v2016_detached Attachment Justification At Top = Minimum Intersection Image = <None> Offset From Attachment At Top = 0 id = 606151 Category Name = Structural Columns Family Name = Concrete-Square-Column Type Name = EXIST RH C2 16 x 16 Document = 15050 Peavy Struct v2016_detached

Python Pandas: Error tokenizing data. C error: EOF inside string starting when reading 1GB CSV file

谁说胖子不能爱 提交于 2020-03-22 06:23:52
问题 I'm reading a 1 GB CSV file in chunks of 10,000 rows. The file has 1106012 rows and 171 columns, other smaller sized file does not show any error and finish off successfully but when i read this 1 GB file it shows error every time on exactly line number 1106011 which is a second last line of file, i can manually remove that line but that is not the solution because i have hundreds of other file of that same size and i cannot fix all the lines manually. can anyone help me with that please. def

SQL*Loader

老子叫甜甜 提交于 2020-03-21 21:51:03
業務で大量データをテーブルに投入する必要があり SQL * Loader を使った。その際に調べた内容を備忘録として残しておきます。 SQL Loader とは? 固定長や CSV 形式の外部ファイルから Oracle データベースにロードするユーティリティ。制御ファイルで指定した内容をもとにデータファイルのデータをデータベースに格納する。 データファイル ロードするデータを保持するファイル。固定長や CSV 形式等を指定することができる。 制御ファイル データファイルの場所やデータの解釈方法などロードに必要な制御情報を保持するファイル ログファイル ロード件数やエラーログなどが記録される。 不良ファイル エラーによりロードされなかったレコードが記録される 廃棄ファイル エラー以外の理由でロードされなかったレコードが記録される 制御ファイル記述例 サンプルテーブル CREATE TABLE EMP ( EMPNO NUMBER(4) NOT NULL, ENAME VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7,2), COMM NUMBER(7,2), DEPTNO NUMBER(2), CONSTRAINT PK_EMP PRIMARY KEY(EMPNO) ) / CSV

SAS proc export to CSV: how to add double quotes

隐身守侯 提交于 2020-03-21 16:29:19
问题 New to this, so apologies. I have a file in SAS that I need to export as a CSV and I need to add double quotes to all fields. How can I accomplish this? Thanks in advance. 回答1: There are many ways to create a CSV file from SAS. Using proc export won't wrap every field in double-quotes, so the easiest one that will do this is the %ds2csv() macro. This assumes you have SAS 9.2 or later. The documentation for it can be found here: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML

seldom之数据驱动

寵の児 提交于 2020-03-21 12:00:51
seldom之数据驱动 如果自动化某个功能,测试数据不一样而操作步骤是一样的,那么就可以使用参数化来节省测试代码。 seldom是我在维护一个Web UI自动化测试框,这里跟大家分享seldom参数化的实现。 GitHub:https://github.com/SeldomQA/seldom 参数化测试用例 import seldom from seldom import data class BaiduTest(seldom.TestCase): @data([ ("case1", "seldom"), ("case2", "selenium"), ("case3", "unittest"), ]) def test_baidu(self, name, keyword): """ 参数化测试用例 :param name: 用例名称 :param keyword: 搜索关键字 """ self.open("https://www.baidu.com") self.type(id_="kw", text=keyword) self.click(css="#su") self.assertTitle(keyword+"_百度搜索") if __name__ == '__main__': seldom.main() 通过 @data() 装饰器来参数化测试用例,用法非常简单。

Filtering and displaying a CSV file with PHP

一曲冷凌霜 提交于 2020-03-21 07:21:07
问题 I am currently retrieving a CSV file with PHP and displaying it in a table format via the following method: <?php if (($file_handle = fopen("data.csv", "r")) !== false) { $str = ''; $str .= '<table>'; while (($data = fgetcsv($file_handle, 1024, ",")) !== false) { $str .= '<tr>'; foreach ($data as $key => &$value) { $str .= "<td valign='top'>$value</td>"; } $str .= '</tr>'; $str .= '<tr><td><br></td></tr>'; } fclose($file_handle); $str .= '</table>'; echo $str; } ?> This works fine and is nice

How could I convert a simple XML to CSV using Python?

谁说胖子不能爱 提交于 2020-03-21 06:36:35
问题 This is my XML file test.xml : <nodes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/nodes_file.xsd"> <node id="0" x="0.0" y="0.0" type="traffic_light"/> <node id="1" x="0.0" y="500.0" type="priority"/> <node id="2" x="500.0" y="0.0" type="priority"/> <node id="3" x="0.0" y="-500.0" type="priority"/> <node id="4" x="-500.0" y="0.0" type="priority"/> </nodes> I want to convert it to a CSV file which contains the following columns: id

How to save output of for loop in separate csv files?

时间秒杀一切 提交于 2020-03-21 06:22:52
问题 As an image and code that I attached below, I have a set of transaction data and each row has its industry name. reproducible example data: structure(list(Date = c(1201, 1201, 1201, 1201, 1201, 1201, 1201, 1201, 1201, 1201), Sex = c("Male", "Male", "Female", "Male", "Male", "Female", "Male", "Female", "Male", "Male"), Age = c(10, 15, 20, 15, 40, 50, 20, 30, 50, 20), City = c("Pheonix", "Atlanta", "Las Vegas", "Las Vegas", "Denver", "Pheonix", "Atlanta", "Las Vegas", "Las Vegas", "Minneapolis"

MongoDB: Issue when using mongoexport with --query option

夙愿已清 提交于 2020-03-21 04:52:53
问题 When I try to take backup with mongoexport using the --query option to get the documents whose status is equal to A, facing the below error: mongoexport --port 27017 --db ex --collection A --type=csv --fields _id,status --query '{"status":"A"}' -o eg.csv error validating settings: query ''{status:A}'' is not valid JSON Please let me know how to use --query option. 回答1: Assuming you run this from the DOS command prompt, you need to swap the single and double quotes. You need to wrap the entire