读取csv的代码:

print pd.read_csv("ex1.csv")

print "\n"
print "Can also use read table with a specific separator"
print pd.read_table("ex1.csv",sep=',') print "\n"
print "Read a csv and define a row as its header"
print pd.read_csv("ex2.csv",header=None)
print "###"
print pd.read_csv("ex2.csv",header=1) print "\n"
print 'Set names for the columns'
name=['wang','li','zhao','qian','sun']
print pd.read_csv('ex2.csv',names=name) print "\n"
print 'Set names for the columns and user a column as the index'
print pd.read_csv('ex2.csv',names=name,index_col='sun')

读取不规则csv到pandas

b = list(open('ex3.txt'))
print b
print 'User regex to split, s represents space,tap,new line, and so forth'
result = pd.read_table('ex3.txt',sep="\s+")
print result print '\n'
print 'Skip rows from reading'
result1 = pd.read_table('ex3.txt',sep="\s+",skiprows=[1,3])
print result1 print '\n'
print 'We found some NaN somewhere'
csv5 = pd.read_csv('ex5.csv')
print csv5
print pd.isnull(csv5) print '\n'
print "We treat 'foo' as a NaN"
csv5_fill = pd.read_csv('ex5.csv',na_values=["foo"])
print csv5_fill

DataFrame读取CSV文件的更多相关文章

  1. python-pandas读取mongodb、读取csv文件

    续上一篇博客(‘’selenium爬取NBA并将数据存储到MongoDB‘)https://www.cnblogs.com/lutt/p/10810581.html 本篇的内容是将存储到mongo的数 ...

  2. pandas-19 DataFrame读取写入文件的方法

    pandas-19 DataFrame读取写入文件的方法 DataFrame有非常丰富的IO方法,比如DataFrame读写csv文件excel文件等等,操作很简单.下面在代码中标记出来一些常用的读写 ...

  3. sparkR读取csv文件

    sparkR读取csv文件 The general method for creating SparkDataFrames from data sources is read.df. This met ...

  4. VB6.0 读取CSV文件

    最近做了一个Upload文件的需求,文件的格式为CSV,读取文件的方法整理了一下,如下: 1.先写了一个读取CSV文件的Function: '读取CSV文件 '假设传入的参数strFile=C:\Do ...

  5. php读取csv文件,在linux上出现中文读取不到的情况 解决方法

    今,php读取csv文件,在linux上出现中文读取不到的情况,google,后找到解决办法<?phpsetlocale(LC_ALL, 'zh_CN');$row = 1;$handle = ...

  6. 使用univocity-parsers创建和读取csv文件

    import com.univocity.parsers.csv.CsvFormat;import com.univocity.parsers.csv.CsvParser;import com.uni ...

  7. Python 读取csv文件到excel

    朋友问我如何通过python把csv格式的文件另存为xls文件,自己想了想通过读取csv文件然后再保存到xls文件中即可,也许还有其他简单的方法,但这里也为了练习python语法及其他知识,所以采用了 ...

  8. 转换成CSV文件、Word、Excel、PDF等的方法--读取CSV文件的方法

    1. 转换成CSV文件: http://www.dotnetgallery.com/lab/resource93-Export-to-CSV-file-from-Data-Table-in-Aspne ...

  9. java读取CSV文件添加到sqlserver数据库

    在直接将CSV文件导入sqlserver数据库时出现了错误,原因还未找到,初步怀疑是数据中含有特殊字符.于是只能用代码导数据了. java读取CSV文件的代码如下: package experimen ...

随机推荐

  1. CSS最基础的语法和三种引入方式

    **CSS语法** CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明.选择器通常是您需要改变样式的 HTML 元素. selector {declaration1; declaration ...

  2. 使用iconv提示未知错误

    使用iconv 转化编码的时候提示错误:<b>Notice</b>: iconv() [<a href='http://www.jinyuanbao.cn'>fun ...

  3. Android深度探索-卷1第六章心得体会

    这章主要介绍了第一个linux驱动程序:统计单词个数.Linux系统将每一个驱动都映射成一个文件,这些文件称为设备文件或驱动文件,都保存在/dev目录中.大多数Linux驱动都有与其对应的设备文件,因 ...

  4. 定制xfce4桌面==排除appfinder的綑绑

    如下等同于安装 xfce4-meta,除了不安装 app-finder emerge -avq xfwm4 xfdesktop xfce4-session xfce4-settings xfce4-t ...

  5. django4-模板,templates

    如何使用templates呢? 在views.py文件中,函数或者方法通过return render(request,"userInfor.html",{"info_li ...

  6. JavaScript HashTable

    function HashTable() { var loseHashCode = function(key) { var hash = 0; for (var i = 0; i < key.l ...

  7. Codeforces Paths and Trees

    Paths and Trees time limit per test3 seconds memory limit per test256 megabytes Little girl Susie ac ...

  8. 灵活轻便的Table控件,适合复杂样式的内容排版

    github仓库地址 https://github.com/gaoyangclub/GYTableViewController 前言 TableView是在项目开发的时候经常用到的组件,几乎百分之八十 ...

  9. 2018-2-13-win10-UWP-你写我读

    title author date CreateTime categories win10 UWP 你写我读 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17: ...

  10. go语言从例子开始之Example17.指针

    Go 支持 指针,允许在程序中通过引用传递值或者数据结构 Example: package main import "fmt" func zeroval(ival int){ iv ...