Data analysis visualization + (2)

Data started trilogy

1. Understand the data size
df.shape

2. Review the first few lines of / the last few lines of data
df.head ()
df.tail ()

3. See data type missing values
df.info ()
This function can be seen from the data type of each column, the number of missing values

Date type variable processing

1. Package guide

import calendar
from datetime import datetime

2. Obtain a list of Monday to Sunday

calendar.day_name[:]

Calendar introduced in day_name, include Monday to Sunday

3. The time to convert a string datetime type

# 使用datatime中的striptime函数将字符串转换为日期时间类型
# 注意这里的datatime是一个包不是我们dataframe里的变量名
# 使用"%Y-%m-%d"来指定输入日期的格式是按照年月日排序,有时候可能会有月日年的排序形式
# dateString是字符串时间,比如2011-01-01
dateDT = datetime.strptime(dateString,"%Y-%m-%d")

#使用转换好的日期时间得到对应的星期几标签 0-6
week_day = dateDT.weekday()
#使用转换好的日期时间得到对应的月份标签 1-12
month = dateDT.month()

Visualization

Figure 1. Multiple painted on a canvas

#建立画布,并设置大小
fig = plt.figure(figsize = (18, 5))

#添加子图1
ax1 = fig.add_subplot(121) #1行两列 第1张图
sns.boxplot(data=BikeData, y="count")
ax1.set(ylabel='',title="") #设置标签
#添加子图2
ax2 = fig.add_subplot(122) #1行两列 第2张图
sns.boxplot(data=BikeData, y="count")
ax2.set(ylabel='',title="") #设置标签
#以此类推~
#

2. The correlation coefficient calculation and visualization

(1) See correlation coefficient matrix
function:
df.corr () # Look correlation coefficient may be set in several columns
(2) The coefficient matrix Videos FIG thermodynamic
function:
sns.heatmap (Correlation, Vmax = .8, True Square = , annot = True) #correlation correlation coefficient matrix

3. Scatter
df.lmplot ()

# New knowledge, the slope of curve fitting may reflect the correlation coefficient
df.regplot ()

4. Multi classification mapping function relearning

sns.FacetGrid(data = BikeData, size=8, aspect=1.5).\
    map(sns.pointplot, 'hour', 'count','weekday', palette='deep', ci=None).\
    add_legend()
 # 'hour', 'count','weekday'按顺序分别是 横坐标-hour,纵坐标-count,分类-weekday

Published 29 original articles · won praise 12 · views 10000 +

Guess you like

Origin blog.csdn.net/c2250645962/article/details/96769104