Pandas中DataFrame的属性

1.读取CSV文件中的数据。

from pandas import read_csv

df = read_csv('WHO_first9cols.csv')

csv文件保存在python程序所在文件,.名称调用类的属性。

2…shape属性
查询DF的形状,多少行多少列。

print('Dataframe', df.shape)
Dataframe (202, 9)

3.len()
查询DF的行数,即多少行。

print('Dataframe', len(df))
Dataframe 202

4…columns
查询DF的各列标题与数据类型

print('Dataframe', df.columns)
Dataframe Index(['Country', 'CountryID', 'Continent', 'Adolescent fertility rate (%)',
       'Adult literacy rate (%)',
       'Gross national income per capita (PPP international $)',
       'Net primary school enrolment ratio female (%)',
       'Net primary school enrolment ratio male (%)',
       'Population (in thousands) total'],
      dtype='object')

5…index
查询DF的索引

print('Dataframe', df.index)
Dataframe RangeIndex(start=0, stop=202, step=1)

6…values
查询DF的数据具体内容

print('Dataframe', df.values)
Dataframe [['Afghanistan' 1 1 ... nan nan 26088.0]
 ['Albania' 2 2 ... 93.0 94.0 3172.0]
 ['Algeria' 3 3 ... 94.0 96.0 33351.0]
 ...
 ['Yemen' 200 1 ... 65.0 85.0 21732.0]
 ['Zambia' 201 3 ... 94.0 90.0 11696.0]
 ['Zimbabwe' 202 3 ... 88.0 87.0 13228.0]]
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值