处理数据的时候往往需要对原始数据进行类型转换和预览等操作,下面介绍常用的处理预览和数据转换方法

预览:例:

import pandas as pd
sec_weather = pd.read_table(r'D:\weather.csv',sep=',')
sec_weather.head()

如果只需要预览数据的几行信息,可以使用head方法和tail方法。head方法返回数据集的开头5行,tail方法返回数据集的末尾5行。

还可以进一步查看数据集有多少观测和多少变量,以及每个月变量都是什么数据类型。例如:

print('数据集的行列数:\n',sec_weather.shape)
print('各变量的数据类型:\n',sec_weather.dtypes)

通过得出的结论可以看出各数据的类型,可对各数据类型进行进行转换

例如:

pd.to_datatime(sec_weather.xxx,format = '%Y年%m月')

sec_weather.xxx.str[:-1].astype('float')

sec_weather.dtypes

 

描述性统计  describe()

sec_weather.describe()

pandas 数据类型转换及描述统计

 

通过基本的统计量(如最小值,均值,中位数,最大值等)描述数据的特征。

 

相关文章:

  • 2021-10-19
  • 2022-12-23
  • 2021-08-21
  • 2021-04-14
  • 2022-12-23
  • 2021-05-21
  • 2021-08-04
  • 2021-09-08
猜你喜欢
  • 2021-05-13
  • 2022-12-23
  • 2022-12-23
  • 2022-02-06
  • 2021-11-07
  • 2021-11-10
相关资源
相似解决方案