用C#写的读取CSV文件的源代码

CSV文件的格子中包含逗号,引号,换行等,都能轻松读取,而且可以把数据转化成DATATABLE格式

  1. using System;
  2. using System.Text;
  3. using System.Collections;
  4. using System.IO;
  5. using System.Data;
  6. using System.Text.RegularExpressions;
  7. using System.Diagnostics;
  8.  
  9. namespace CsvLib
  10. {
  11. #region 类说明信息
  12.  
  13. /// <summary>
  14. /// <DL>
  15. /// <DT><b>读CSV文件类,读取指定的CSV文件,可以导出DataTable</b></DT>
  16. /// <DD>
  17. /// <UL>
  18. /// </UL>
  19. /// </DD>
  20. /// </DL>
  21. /// <Author>yangzhihong</Author>
  22. /// <CreateDate>2006/01/16</CreateDate>
  23. /// <Company></Company>
  24. /// <Version>1.0</Version>
  25. /// </summary>
  26. #endregion
  27. public class CsvStreamReader
  28. {
  29. private ArrayList rowAL; //行链表,CSV文件的每一行就是一个链
  30. private string fileName; //文件名
  31.  
  32. private Encoding encoding; //编码
  33.  
  34. public CsvStreamReader()
  35. {
  36. this.rowAL = new ArrayList();
  37. this.fileName = "";
  38. this.encoding = Encoding.Default;
  39. }
  40.  
  41. /// <summary>
  42. ///
  43. /// </summary>
  44. /// <param name="fileName">文件名,包括文件路径</param>
  45. public CsvStreamReader(string fileName)
  46. {
  47. this.rowAL = new ArrayList();
  48. this.fileName = fileName;
  49. this.encoding = Encoding.Default;
  50. LoadCsvFile();
  51. }
  52.  
  53. /// <summary>
  54. ///
  55. /// </summary>
  56. /// <param name="fileName">文件名,包括文件路径</param>
  57. /// <param name="encoding">文件编码</param>
  58. public CsvStreamReader(string fileName,Encoding encoding)
  59. {
  60. this.rowAL = new ArrayList();
  61. this.fileName = fileName;
  62. this.encoding = encoding;
  63. LoadCsvFile();
  64. }
  65.  
  66. /// <summary>
  67. /// 文件名,包括文件路径
  68. /// </summary>
  69. public string FileName
  70. {
  71. set
  72. {
  73. this.fileName = value;
  74. LoadCsvFile();
  75. }
  76. }
  77.  
  78. /// <summary>
  79. /// 文件编码
  80. /// </summary>
  81.  
  82. public Encoding FileEncoding
  83. {
  84. set
  85. {
  86. this.encoding = value;
  87. }
  88. }
  89.  
  90. /// <summary>
  91. /// 获取行数
  92. /// </summary>
  93. public int RowCount
  94. {
  95. get
  96. {
  97. return this.rowAL.Count;
  98. }
  99. }
  100.  
  101. /// <summary>
  102. /// 获取列数
  103. /// </summary>
  104. public int ColCount
  105. {
  106. get
  107. {
  108. int maxCol;
  109.  
  110. maxCol = 0;
  111. for (int i = 0;i<this.rowAL.Count;i++)
  112. {
  113. ArrayList colAL = (ArrayList) this.rowAL[i];
  114.  
  115. maxCol = (maxCol > colAL.Count)?maxCol:colAL.Count;
  116. }
  117.  
  118. return maxCol;
  119. }
  120. }
  121.  
  122. /// <summary>
  123. /// 获取某行某列的数据
  124.  
  125. /// row:行,row = 1代表第一行
  126.  
  127. /// col:列,col = 1代表第一列
  128. /// </summary>
  129. public string this[int row,int col]
  130. {
  131. get
  132. {
  133. //数据有效性验证
  134.  
  135. CheckRowValid(row);
  136. CheckColValid(col);
  137. ArrayList colAL = (ArrayList) this.rowAL[row-1];
  138.  
  139. //如果请求列数据大于当前行的列时,返回空值
  140.  
  141. if (colAL.Count < col)
  142. {
  143. return "";
  144. }
  145.  
  146. return colAL[col-1].ToString();
  147. }
  148. }
  149.  
  150. /// <summary>
  151. /// 根据最小行,最大行,最小列,最大列,来生成一个DataTable类型的数据
  152.  
  153. /// 行等于1代表第一行
  154.  
  155. /// 列等于1代表第一列
  156.  
  157. /// maxrow: -1代表最大行
  158. /// maxcol: -1代表最大列
  159. /// </summary>
  160. public DataTable this[int minRow,int maxRow,int minCol,int maxCol]
  161. {
  162. get
  163. {
  164. //数据有效性验证
  165.  
  166. CheckRowValid(minRow);
  167. CheckMaxRowValid(maxRow);
  168. CheckColValid(minCol);
  169. CheckMaxColValid(maxCol);
  170. if (maxRow == -1)
  171. {
  172. maxRow = RowCount;
  173. }
  174. if (maxCol == -1)
  175. {
  176. maxCol = ColCount;
  177. }
  178. if (maxRow < minRow)
  179. {
  180. throw new Exception("最大行数不能小于最小行数");
  181. }
  182. if (maxCol < minCol)
  183. {
  184. throw new Exception("最大列数不能小于最小列数");
  185. }
  186. DataTable csvDT = new DataTable();
  187. int i;
  188. int col;
  189. int row;
  190.  
  191. //增加列
  192.  
  193. for (i = minCol;i <= maxCol;i++)
  194. {
  195. csvDT.Columns.Add(i.ToString());
  196. }
  197. for (row = minRow;row <= maxRow;row++)
  198. {
  199. DataRow csvDR = csvDT.NewRow();
  200.  
  201. i = 0;
  202. for (col = minCol;col <=maxCol;col++)
  203. {
  204. csvDR[i] = this[row,col];
  205. i++;
  206. }
  207. csvDT.Rows.Add(csvDR);
  208. }
  209.  
  210. return csvDT;
  211. }
  212. }
  213.  
  214. /// <summary>
  215. /// 检查行数是否是有效的
  216.  
  217. /// </summary>
  218. /// <param name="col"></param>
  219. private void CheckRowValid(int row)
  220. {
  221. if (row <= 0)
  222. {
  223. throw new Exception("行数不能小于0");
  224. }
  225. if (row > RowCount)
  226. {
  227. throw new Exception("没有当前行的数据");
  228. }
  229. }
  230.  
  231. /// <summary>
  232. /// 检查最大行数是否是有效的
  233.  
  234. /// </summary>
  235. /// <param name="col"></param>
  236. private void CheckMaxRowValid(int maxRow)
  237. {
  238. if (maxRow <= 0 && maxRow != -1)
  239. {
  240. throw new Exception("行数不能等于0或小于-1");
  241. }
  242. if (maxRow > RowCount)
  243. {
  244. throw new Exception("没有当前行的数据");
  245. }
  246. }
  247.  
  248. /// <summary>
  249. /// 检查列数是否是有效的
  250.  
  251. /// </summary>
  252. /// <param name="col"></param>
  253. private void CheckColValid(int col)
  254. {
  255. if (col <= 0)
  256. {
  257. throw new Exception("列数不能小于0");
  258. }
  259. if (col > ColCount)
  260. {
  261. throw new Exception("没有当前列的数据");
  262. }
  263. }
  264.  
  265. /// <summary>
  266. /// 检查检查最大列数是否是有效的
  267.  
  268. /// </summary>
  269. /// <param name="col"></param>
  270. private void CheckMaxColValid(int maxCol)
  271. {
  272. if (maxCol <= 0 && maxCol != -1)
  273. {
  274. throw new Exception("列数不能等于0或小于-1");
  275. }
  276. if (maxCol > ColCount)
  277. {
  278. throw new Exception("没有当前列的数据");
  279. }
  280. }
  281.  
  282. /// <summary>
  283. /// 载入CSV文件
  284. /// </summary>
  285. private void LoadCsvFile()
  286. {
  287. //对数据的有效性进行验证
  288.  
  289. if (this.fileName == null)
  290. {
  291. throw new Exception("请指定要载入的CSV文件名");
  292. }
  293. else if (!File.Exists(this.fileName))
  294. {
  295. throw new Exception("指定的CSV文件不存在");
  296. }
  297. else
  298. {
  299. }
  300. if (this.encoding == null)
  301. {
  302. this.encoding = Encoding.Default;
  303. }
  304.  
  305. StreamReader sr = new StreamReader(this.fileName,this.encoding);
  306. string csvDataLine;
  307.  
  308. csvDataLine = "";
  309. while (true)
  310. {
  311. string fileDataLine;
  312.  
  313. fileDataLine = sr.ReadLine();
  314. if (fileDataLine == null)
  315. {
  316. break;
  317. }
  318. if (csvDataLine == "")
  319. {
  320. csvDataLine = fileDataLine;//GetDeleteQuotaDataLine(fileDataLine);
  321. }
  322. else
  323. {
  324. csvDataLine += "/r/n" + fileDataLine;//GetDeleteQuotaDataLine(fileDataLine);
  325. }
  326. //如果包含偶数个引号,说明该行数据中出现回车符或包含逗号
  327. if (!IfOddQuota(csvDataLine))
  328. {
  329. AddNewDataLine(csvDataLine);
  330. csvDataLine = "";
  331. }
  332. }
  333. sr.Close();
  334. //数据行出现奇数个引号
  335. if (csvDataLine.Length > 0)
  336. {
  337. throw new Exception("CSV文件的格式有错误");
  338. }
  339. }
  340.  
  341. /// <summary>
  342. /// 获取两个连续引号变成单个引号的数据行
  343. /// </summary>
  344. /// <param name="fileDataLine">文件数据行</param>
  345. /// <returns></returns>
  346. private string GetDeleteQuotaDataLine(string fileDataLine)
  347. {
  348. return fileDataLine.Replace("/"/"","/"");
  349. }
  350.  
  351. /// <summary>
  352. /// 判断字符串是否包含奇数个引号
  353. /// </summary>
  354. /// <param name="dataLine">数据行</param>
  355. /// <returns>为奇数时,返回为真;否则返回为假</returns>
  356. private bool IfOddQuota(string dataLine)
  357. {
  358. int quotaCount;
  359. bool oddQuota;
  360.  
  361. quotaCount = 0;
  362. for (int i = 0;i < dataLine.Length;i++)
  363. {
  364. if (dataLine[i] == '/"')
  365. {
  366. quotaCount++;
  367. }
  368. }
  369.  
  370. oddQuota = false;
  371. if (quotaCount % 2 == 1)
  372. {
  373. oddQuota = true;
  374. }
  375.  
  376. return oddQuota;
  377. }
  378.  
  379. /// <summary>
  380. /// 判断是否以奇数个引号开始
  381.  
  382. /// </summary>
  383. /// <param name="dataCell"></param>
  384. /// <returns></returns>
  385. private bool IfOddStartQuota(string dataCell)
  386. {
  387. int quotaCount;
  388. bool oddQuota;
  389.  
  390. quotaCount = 0;
  391. for (int i = 0;i < dataCell.Length;i++)
  392. {
  393. if (dataCell[i] == '/"')
  394. {
  395. quotaCount++;
  396. }
  397. else
  398. {
  399. break;
  400. }
  401. }
  402.  
  403. oddQuota = false;
  404. if (quotaCount % 2 == 1)
  405. {
  406. oddQuota = true;
  407. }
  408.  
  409. return oddQuota;
  410. }
  411.  
  412. /// <summary>
  413. /// 判断是否以奇数个引号结尾
  414. /// </summary>
  415. /// <param name="dataCell"></param>
  416. /// <returns></returns>
  417. private bool IfOddEndQuota(string dataCell)
  418. {
  419. int quotaCount;
  420. bool oddQuota;
  421.  
  422. quotaCount = 0;
  423. for (int i = dataCell.Length -1;i >= 0;i--)
  424. {
  425. if (dataCell[i] == '/"')
  426. {
  427. quotaCount++;
  428. }
  429. else
  430. {
  431. break;
  432. }
  433. }
  434.  
  435. oddQuota = false;
  436. if (quotaCount % 2 == 1)
  437. {
  438. oddQuota = true;
  439. }
  440.  
  441. return oddQuota;
  442. }
  443.  
  444. /// <summary>
  445. /// 加入新的数据行
  446.  
  447. /// </summary>
  448. /// <param name="newDataLine">新的数据行</param>
  449. private void AddNewDataLine(string newDataLine)
  450. {
  451. Debug.WriteLine("NewLine:" + newDataLine);
  452.  
  453. //return;
  454.  
  455. ArrayList colAL = new ArrayList();
  456. string[] dataArray = newDataLine.Split(',');
  457. bool oddStartQuota; //是否以奇数个引号开始
  458.  
  459. string cellData;
  460.  
  461. oddStartQuota = false;
  462. cellData = "";
  463. for (int i = 0 ;i < dataArray.Length;i++)
  464. {
  465. if (oddStartQuota)
  466. {
  467. //因为前面用逗号分割,所以要加上逗号
  468. cellData += "," + dataArray[i];
  469. //是否以奇数个引号结尾
  470. if (IfOddEndQuota(dataArray[i]))
  471. {
  472. colAL.Add(GetHandleData(cellData));
  473. oddStartQuota = false;
  474. continue;
  475. }
  476. }
  477. else
  478. {
  479. //是否以奇数个引号开始
  480.  
  481. if (IfOddStartQuota(dataArray[i]))
  482. {
  483. //是否以奇数个引号结尾,不能是一个双引号,并且不是奇数个引号
  484.  
  485. if (IfOddEndQuota(dataArray[i]) && dataArray[i].Length > 2 && !IfOddQuota(dataArray[i]))
  486. {
  487. colAL.Add(GetHandleData(dataArray[i]));
  488. oddStartQuota = false;
  489. continue;
  490. }
  491. else
  492. {
  493.  
  494. oddStartQuota = true;
  495. cellData = dataArray[i];
  496. continue;
  497. }
  498. }
  499. else
  500. {
  501. colAL.Add(GetHandleData(dataArray[i]));
  502. }
  503. }
  504. }
  505. if (oddStartQuota)
  506. {
  507. throw new Exception("数据格式有问题");
  508. }
  509. this.rowAL.Add(colAL);
  510. }
  511.  
  512. /// <summary>
  513. /// 去掉格子的首尾引号,把双引号变成单引号
  514.  
  515. /// </summary>
  516. /// <param name="fileCellData"></param>
  517. /// <returns></returns>
  518. private string GetHandleData(string fileCellData)
  519. {
  520. if (fileCellData == "")
  521. {
  522. return "";
  523. }
  524. if (IfOddStartQuota(fileCellData))
  525. {
  526. if (IfOddEndQuota(fileCellData))
  527. {
  528. return fileCellData.Substring(1,fileCellData.Length-2).Replace("/"/"","/""); //去掉首尾引号,然后把双引号变成单引号
  529. }
  530. else
  531. {
  532. throw new Exception("数据引号无法匹配" + fileCellData);
  533. }
  534. }
  535. else
  536. {
  537. //考虑形如"" """" """"""
  538. if (fileCellData.Length >2 && fileCellData[0] == '/"')
  539. {
  540. fileCellData = fileCellData.Substring(1,fileCellData.Length-2).Replace("/"/"","/""); //去掉首尾引号,然后把双引号变成单引号
  541. }
  542. }
  543.  
  544. return fileCellData;
  545. }
  546. }
  547. }
  548.  
  549. using System;
  550. using System.Text;
  551. using System.Collections;
  552. using System.IO;
  553. using System.Data;
  554.  
  555. namespace CsvLib
  556. {
  557. #region 类说明信息
  558. /// <summary>
  559. /// <DL>
  560. /// <DT><b>写CSV文件类,首先给CSV文件赋值,最后通过Save方法进行保存操作</b></DT>
  561. /// <DD>
  562. /// <UL>
  563. /// </UL>
  564. /// </DD>
  565. /// </DL>
  566. /// <Author>yangzhihong</Author>
  567. /// <CreateDate>2006/01/16</CreateDate>
  568. /// <Company></Company>
  569. /// <Version>1.0</Version>
  570. /// </summary>
  571. #endregion
  572. public class CsvStreamWriter
  573. {
  574. private ArrayList rowAL; //行链表,CSV文件的每一行就是一个链
  575. private string fileName; //文件名
  576. private Encoding encoding; //编码
  577.  
  578. public CsvStreamWriter()
  579. {
  580. this.rowAL = new ArrayList();
  581. this.fileName = "";
  582. this.encoding = Encoding.Default;
  583. }
  584.  
  585. /// <summary>
  586. ///
  587. /// </summary>
  588. /// <param name="fileName">文件名,包括文件路径</param>
  589. public CsvStreamWriter(string fileName)
  590. {
  591. this.rowAL = new ArrayList();
  592. this.fileName = fileName;
  593. this.encoding = Encoding.Default;
  594. }
  595.  
  596. /// <summary>
  597. ///
  598. /// </summary>
  599. /// <param name="fileName">文件名,包括文件路径</param>
  600. /// <param name="encoding">文件编码</param>
  601. public CsvStreamWriter(string fileName,Encoding encoding)
  602. {
  603. this.rowAL = new ArrayList();
  604. this.fileName = fileName;
  605. this.encoding = encoding;
  606. }
  607.  
  608. /// <summary>
  609. /// row:行,row = 1代表第一行
  610. /// col:列,col = 1代表第一列
  611. /// </summary>
  612. public string this[int row,int col]
  613. {
  614. set
  615. {
  616. //对行进行判断
  617. if (row <= 0)
  618. {
  619. throw new Exception("行数不能小于0");
  620. }
  621. else if (row > this.rowAL.Count) //如果当前列链的行数不够,要补齐
  622. {
  623. for (int i = this.rowAL.Count + 1;i <= row;i++)
  624. {
  625. this.rowAL.Add(new ArrayList());
  626. }
  627. }
  628. else
  629. {
  630. }
  631. //对列进行判断
  632. if (col <= 0)
  633. {
  634. throw new Exception("列数不能小于0");
  635. }
  636. else
  637. {
  638. ArrayList colTempAL = (ArrayList) this.rowAL[row-1];
  639.  
  640. //扩大长度
  641. if (col > colTempAL.Count)
  642. {
  643. for (int i = colTempAL.Count;i <= col;i++)
  644. {
  645. colTempAL.Add("");
  646. }
  647. }
  648. this.rowAL[row-1] = colTempAL;
  649. }
  650. //赋值
  651. ArrayList colAL = (ArrayList) this.rowAL[row-1];
  652.  
  653. colAL[col-1] = value;
  654. this.rowAL[row-1] = colAL;
  655. }
  656. }
  657.  
  658. /// <summary>
  659. /// 文件名,包括文件路径
  660. /// </summary>
  661. public string FileName
  662. {
  663. set
  664. {
  665. this.fileName = value;
  666. }
  667. }
  668.  
  669. /// <summary>
  670. /// 文件编码
  671. /// </summary>
  672.  
  673. public Encoding FileEncoding
  674. {
  675. set
  676. {
  677. this.encoding = value;
  678. }
  679. }
  680.  
  681. /// <summary>
  682. /// 获取当前最大行
  683. /// </summary>
  684. public int CurMaxRow
  685. {
  686. get
  687. {
  688. return this.rowAL.Count;
  689. }
  690. }
  691.  
  692. /// <summary>
  693. /// 获取最大列
  694. /// </summary>
  695. public int CurMaxCol
  696. {
  697. get
  698. {
  699. int maxCol;
  700.  
  701. maxCol = 0;
  702. for (int i = 0;i<this.rowAL.Count;i++)
  703. {
  704. ArrayList colAL = (ArrayList) this.rowAL[i];
  705.  
  706. maxCol = (maxCol > colAL.Count)?maxCol:colAL.Count;
  707. }
  708.  
  709. return maxCol;
  710. }
  711. }
  712.  
  713. /// <summary>
  714. /// 添加表数据到CSV文件中
  715. /// </summary>
  716. /// <param name="dataDT">表数据</param>
  717. /// <param name="beginCol">从第几列开始,beginCol = 1代表第一列</param>
  718. public void AddData(DataTable dataDT,int beginCol)
  719. {
  720. if (dataDT == null)
  721. {
  722. throw new Exception("需要添加的表数据为空");
  723. }
  724. int curMaxRow;
  725.  
  726. curMaxRow = this.rowAL.Count;
  727. for (int i = 0;i < dataDT.Rows.Count;i++)
  728. {
  729. for (int j = 0;j <dataDT.Columns.Count;j++)
  730. {
  731. this[curMaxRow + i + 1,beginCol + j] = dataDT.Rows[i][j].ToString();
  732. }
  733. }
  734. }
  735.  
  736. /// <summary>
  737. /// 保存数据,如果当前硬盘中已经存在文件名一样的文件,将会覆盖
  738. /// </summary>
  739. public void Save()
  740. {
  741. //对数据的有效性进行判断
  742. if (this.fileName == null)
  743. {
  744. throw new Exception("缺少文件名");
  745. }
  746. else if (File.Exists(this.fileName))
  747. {
  748. File.Delete(this.fileName);
  749. }
  750. if (this.encoding == null)
  751. {
  752. this.encoding = Encoding.Default;
  753. }
  754. System.IO.StreamWriter sw = new StreamWriter(this.fileName,false,this.encoding);
  755.  
  756. for (int i = 0 ;i < this.rowAL.Count;i++)
  757. {
  758. sw.WriteLine(ConvertToSaveLine((ArrayList) this.rowAL[i]));
  759. }
  760.  
  761. sw.Close();
  762. }
  763.  
  764. /// <summary>
  765. /// 保存数据,如果当前硬盘中已经存在文件名一样的文件,将会覆盖
  766. /// </summary>
  767. /// <param name="fileName">文件名,包括文件路径</param>
  768. public void Save(string fileName)
  769. {
  770. this.fileName = fileName;
  771. Save();
  772. }
  773.  
  774. /// <summary>
  775. /// 保存数据,如果当前硬盘中已经存在文件名一样的文件,将会覆盖
  776. /// </summary>
  777. /// <param name="fileName">文件名,包括文件路径</param>
  778. /// <param name="encoding">文件编码</param>
  779. public void Save(string fileName,Encoding encoding)
  780. {
  781. this.fileName = fileName;
  782. this.encoding = encoding;
  783. Save();
  784. }
  785.  
  786. /// <summary>
  787. /// 转换成保存行
  788. /// </summary>
  789. /// <param name="colAL">一行</param>
  790. /// <returns></returns>
  791. private string ConvertToSaveLine(ArrayList colAL)
  792. {
  793. string saveLine;
  794.  
  795. saveLine = "";
  796. for (int i = 0;i< colAL.Count;i++)
  797. {
  798. saveLine += ConvertToSaveCell(colAL[i].ToString());
  799. //格子间以逗号分割
  800. if (i < colAL.Count - 1)
  801. {
  802. saveLine += ",";
  803. }
  804. }
  805.  
  806. return saveLine;
  807. }
  808.  
  809. /// <summary>
  810. /// 字符串转换成CSV中的格子
  811. /// 双引号转换成两个双引号,然后首尾各加一个双引号
  812. /// 这样就不需要考虑逗号及换行的问题
  813. /// </summary>
  814. /// <param name="cell">格子内容</param>
  815. /// <returns></returns>
  816. private string ConvertToSaveCell(string cell)
  817. {
  818. cell = cell.Replace("/"","/"/"");
  819.  
  820. return "/"" + cell + "/"";
  821. }
  822. }
  823. }

用C#写的读写CSV文件的更多相关文章

  1. 用opencsv文件读写CSV文件

    首先明白csv文件长啥样儿: 用excel打开就变成表格了,看不到细节 推荐用其它简单粗暴一点儿的编辑器,比如Notepad++, csv文件内容如下: csv文件默认用逗号分隔各列. 有了基础的了解 ...

  2. python3读写csv文件

    python读取CSV文件   python中有一个读写csv文件的包,直接import csv即可.利用这个python包可以很方便对csv文件进行操作,一些简单的用法如下. 1. 读文件 csv_ ...

  3. 利用JavaCSV API来读写csv文件

    http://blog.csdn.net/loongshawn/article/details/53423121 http://javacsv.sourceforge.net/ 转载请注明来源-作者@ ...

  4. 使用 Apache Commons CSV 读写 CSV 文件

    有时候,我们需要读写 CSV 文件,在这里给大家分享Apache Commons CSV,读写 CSV 文件非常方便. 具体官方文档请访问Apache Commons CSV. 官方文档已经写得很详细 ...

  5. C/C++读写csv文件

    博客转载自:http://blog.csdn.net/u012234115/article/details/64465398 C++ 读写CSV文件,注意一下格式即可 #include <ios ...

  6. JAVA读写CSV文件

    最近工作需要,需要读写CSV文件的数据,简单封装了一下 依赖读写CSV文件只需引用`javacsv`这个依赖就可以了 <dependency> <groupId>net.sou ...

  7. 使用Python读写csv文件的三种方法

    Python读写csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 前言 逗号分隔值(Comma-Separated Values,CSV,有时也称为字符分隔值,因为分隔字符也可以不是 ...

  8. python读写csv文件

    文章链接:https://www.cnblogs.com/cloud-ken/p/8432999.html Python读写csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 前言 逗 ...

  9. Pandas 基础(4) - 读/写 Excel 和 CSV 文件

    这一节将分别介绍读/写 Excel 和 CSV 文件的各种方式: - 读入 CSV 文件 首先是准备一个 csv 文件, 这里我用的是 stock_data.csv, 文件我已上传, 大家可以直接下载 ...

随机推荐

  1. Java是传值还是传引用

    http://www.bccn.net/Article/kfyy/java/jszl/200601/3069.html 对于基本数据类型(整型.浮点型.字符型.布尔型等),传值;对于引用类型(对象.数 ...

  2. Oracle 删除数据后释放数据文件所占磁盘空间

    测试的时候向数据库中插入了大量的数据,测试完成后删除了测试用户以及其全部数据,但是数据文件却没有缩小.经查阅资料之后发现这是 Oracle “高水位”所致,那么怎么把这些数据文件的大小降下来呢?解决办 ...

  3. css选择器nth-child()和nth-of-type()的应用

    <style> .table-striped tbody > tr:nth-child(odd) > td, .table-striped tbody > tr:nth- ...

  4. Laxcus大数据管理系统2.0(14)- 后记

    后记 Laxcus最早源于一个失败的搜索引擎项目,项目最后虽然终止了,但是项目中的部分技术,包括FIXP协议.Diffuse/Converge算法.以及很多新的数据处理理念却得以保留下来,这些成为后来 ...

  5. Win2D 官方文章系列翻译 - DPI (每英寸点数)和 DIPs(设备独立像素)

    本文为个人博客备份文章,原文地址: http://validvoid.net/win2d-dpi-dips/ 本文旨在解释物理像素与设备独立像素(DIPs, device independent pi ...

  6. Android开发-API指南-<application>

    <application> 英文原文:http://developer.android.com/guide/topics/manifest/application-element.html ...

  7. Flash视频播放器开发经验总结

    HTTP协议更优 目前几乎所有的视频点播网站全部采用HTTP协议传输数据.因为相对于诸如RTMP等协议来说,HTTP协议是无状态的,数据传输完毕就断开连接,这样服务器就可以腾出资源来服务更多的用户.而 ...

  8. 学习练习 java 集合

    将1—100之间的所有正整数存放在一个List集合中,并将集合中索引位置是10的对象从集合中移除 package com.hanqi; import java.util.*; public class ...

  9. JavaScript创建表格的两种方式

    方式一: var data = [ { id: 1, name: "first", age: 12 }, { id: 2, name: "second", ag ...

  10. jquery递归遍历xml文件,形成ul-li序列,生成树结构(使用了treeview插件)

    treeview插件从这里获得,下载的文件中有demo,看demo文件夹里面的index.html文件就差不多知道如何使用该控件了,在我做的项目里用到的部分代码截图如下(在引用下面的js文件前要先引用 ...