首页 > 其他 > 详细

pd.dataframe和series以及np.narray的维度升降

时间:2019-09-27 21:16:11      阅读:466      评论:0      收藏:0      [点我收藏+]

 

1.第一步读入泰坦尼克号数据集

import pandas as pd
data = pd.read_csv(r".\Narrativedata.csv"
,index_col=0
)#index_col=0将第0列作为索引,不写则认为第0列为特征

data.head()

技术分享图片

 

 

2.通过df的loc的函数从df中取出一列的数据,该数据格式为  : <class ‘pandas.core.series.Series‘>

age1=data.loc[:,"Age"]
print(type(age1))
age1.head()

技术分享图片

 

 会发现数据维度:(891,)

技术分享图片

 技术分享图片

 

 

3.数据维度的转换 升维

   1.使用Series类的 to_dataframe

print(type(Age.to_frame()))
print(Age.to_frame().shape)
Age.to_frame().head()

技术分享图片

 

  2.使用reshape和values.reshape

age1=Age.reshape(-1,1)

技术分享图片

 

 

 age2=Age.values.reshape(-1,1)

 

技术分享图片

 

 

print(type(age2))
age2.shape

技术分享图片

 

 3.

pd.dataframe和series以及np.narray的维度升降

原文:https://www.cnblogs.com/wqbin/p/11600250.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!