I am trying to create a new dataframe from csv:
frame = DataFrame(data=pd.read_csv(path))
the result is correct except that the first line becomes the columns:
so I add columns to the dtaframe:
columns = ['person-id','time-stamp','loc-id']
frame = DataFrame(data=pd.read_csv(path),columns=columns)
then it goes wrong:the dataframe is all nan
this confuses me,can anyone tell me what is going on with it?
您不需要DataFrame
构造函数,因为read_csv
输出显然是DataFrame
(如果不使用squeeze=True
,则使用Series
):
frame=pd.read_csv(path)
You need to tell read_csv()
that your input has no column headers; by the time you give Dataframe
the column names, it's too late. Try this:
columns = ['person-id','time-stamp','loc-id']
frame = pd.read_csv(path, names=columns)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.