[英]Python Pandas not reading DataFrame
I am trying to read in a csv file into a pandas dataframe and then set the column to the specified columns in columns=[ ... ] 我正在尝试将csv文件读入pandas数据框,然后将该列设置为columns = [...]中的指定列
Would anyone now why its not reading in all of my data? 现在有人会为什么不读取我的所有数据吗? p
p
fp = '/Users/USERNAME/Development/file.csv'
file1 = open(fp, 'rb').read()
reader = pd.DataFrame.from_csv(fp, index_col=False, sep=',')
df = pd.DataFrame(reader, columns=['VIN', 'Reg City','First Name','Last Name','MGVW','Nat Flt Ind','MGVW',
'Reg Name','Phone', 'Unnamed: 8','ZIP','VC','VType',
'Reg Voc', 'Make','Veh Model', 'E Mfr','Engine Model',
'CY2010', 'CY2011', 'CY2012', 'CY2013', 'CY2014', 'CY2015',
'Std Cnt',])
#reader.head(1)
df.head(1)
VIN Reg City First Name Last Name MGVW Nat Flt Ind MGVW Reg Name Phone Unnamed: 8 ... Veh Model E Mfr Engine Model CY2010 CY2011 CY2012 CY2013 CY2014 CY2015 Std Cnt 0 NaN KANSAS NaN NaN NaN N NaN ACE PIPE CLNG INC NaN NaN ... NaN NaN NaN 0 1
VIN Reg City名字MGVW Nat Flt Ind MGVW Reg Name电话未命名:8 ... Veh Model E Mfr Engine Model CY2010 CY2011 CY2012 CY2013 CY2014 CY2015 Std Cnt 0 NaN KANSAS NaN NaN NaN NNN ACE PIPE CLNG INC NaN NaN。 .. NaN NaN NaN 0 1
Just do df = pd.read_csv('/Users/USERNAME/Development/file.csv')
to load your CSV file. 只需执行
df = pd.read_csv('/Users/USERNAME/Development/file.csv')
即可加载CSV文件。 If I am not mistaken, from_csv
as been replaced by read_csv
. 如果我没记错的话,
from_csv
被read_csv
代替。
Here is a version to load only certain colunns. 这是仅加载某些社区的版本。 set
usecols
in pd.read_csv()
. 在
pd.read_csv()
设置usecols
。
import pandas as pd
fp = '/Users/USERNAME/Development/file.csv'
usecols = ['VIN', 'Reg City','First Name','Last Name','MGVW','Nat Flt Ind','MGVW',
'Reg Name','Phone', 'Unnamed: 8','ZIP','VC','VType',
'Reg Voc', 'Make','Veh Model', 'E Mfr','Engine Model',
'CY2010', 'CY2011', 'CY2012', 'CY2013', 'CY2014', 'CY2015',
'Std Cnt']
df = pd.read_csv(fp, usecols=usecols, sep=',')
print df.head()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.