无法读取火车数据

时间:2019-04-30 04:43:43

标签: python pandas data-science

list数据读入变量后,当我尝试使用"train.csv"打印前五行时,它给了我一个错误。

我的代码是:

train.head()

运行它后,我收到错误消息:

  

NameError跟踪(最近的呼叫   最后)   ----> 1 train.head()

     

NameError:名称“ train”未定义

1 个答案:

答案 0 :(得分:0)

我不知道出了什么问题,请尝试以下代码:

import pandas as pd
import numpy as np

train = pd.read_csv(r'http://samplecsvs.s3.amazonaws.com/Sacramentorealestatetransactions.csv',  dtype={'acoustic_data': np.int16, 'time_to_failure': np.float64})
print(train.head())

我得到:

>>>              street        city    zip state  beds  baths  sq__ft  \
>>> 0      3526 HIGH ST  SACRAMENTO  95838    CA     2      1     836   
>>> 1       51 OMAHA CT  SACRAMENTO  95823    CA     3      1    1167   
>>> 2    2796 BRANCH ST  SACRAMENTO  95815    CA     2      1     796   
>>> 3  2805 JANETTE WAY  SACRAMENTO  95815    CA     2      1     852   
>>> 4   6001 MCMAHON DR  SACRAMENTO  95824    CA     2      1     797   
>>> 
>>>           type                     sale_date  price   latitude   longitude  
>>> 0  Residential  Wed May 21 00:00:00 EDT 2008  59222  38.631913 -121.434879  
>>> 1  Residential  Wed May 21 00:00:00 EDT 2008  68212  38.478902 -121.431028  
>>> 2  Residential  Wed May 21 00:00:00 EDT 2008  68880  38.618305 -121.443839  
>>> 3  Residential  Wed May 21 00:00:00 EDT 2008  69307  38.616835 -121.439146  
>>> 4  Residential  Wed May 21 00:00:00 EDT 2008  81900  38.519470 -121.435768  

希望有帮助