好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python导入csv文件出现SyntaxError问题分析_python

这篇文章主要介绍了python导入csv文件出现SyntaxError问题分析,同时涉及python导入csv文件的三种方法,具有一定借鉴价值,对Python感兴趣的朋友可以参考下。

import numpy as np
x = np.loadtxt('C:\Users\sunshine\Desktop\scjym_3yNp3Gj\源数据\000001.csv',delimiter= ',',skiprows=(1),usecols= (1,4,6),unpack= False) 
r'C:\Users\expoperialed\Desktop\Python'
'C:\\Users\\expoperialed\\Desktop\\Python'
'C:/Users/expoperialed/Desktop/Python' 
print('''This is a very long string.
it will continue.
and it's not over yet.
''hello,world''
still here.''' 
#原始的方式
lines = [line.split(',') for line in open('iris.csv')]
df = [[float(x) for x in line[:4]] for line in lines[1:]]
#使用numpy包
import numpy as np
lines = np.loadtxt('iris.csv',delimiter=',',dtype='str')
df = lines[1:,:4].astype('float')
#使用pandas包
import pandas as pd
df = pd.read_csv('iris.csv')
df=df.ix[:,:4] 

这三种方法中最后一种最简单,不过花费时间比较长一点,第一种最麻烦,不过用时最短。这个可以通过ipython中的magic函数 %%timeit 来看。

总结

以上就是本文关于python导入csv文件出现SyntaxError问题分析的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

相关推荐:

用Python语言描述最大连续子序列和

Python爬虫入门心得分享

python版简单工厂模式的介绍

以上就是python导入csv文件出现SyntaxError问题分析_python的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于python导入csv文件出现SyntaxError问题分析_python的详细内容...

  阅读:42次