安装
1 | yum install gperftools gperftools-devel -y |
Heap Profile
1 | dump |
1 | yum install gperftools gperftools-devel -y |
1 | dump |
[toc]
1 | sudo kubeadm reset cleanup-node # master 节点也可以清除 |
1 | 查看 node 标签 |
设置 pod 的 node 标签选择(nodeSelector)
1 | apiVersion: v1 |
设置 deployment node 标签选择
1 | spec: |
1 | kubectl delete --all deployments d-n=<ns> |
1 | 查看 pod 信息 |
1 | 列出所有 service |
1 | microk8s kubectl create token -n kube-system default --duration=8544h |
1 | docker login |
1 | 创建 |
1 | 列出所有的 namespace |
1 | kubectl exec --stdin --tty <pod-instance> -- /bin/bash |
float [0, 1]
绘制子图。
原型
1 | subplot(nrows, ncols, index, **kwargs) |
示例
1 | import matplotlib.pyplot as plt |
1 | # 数据来自鸢尾花数据集,绘制散点图 |
Matplotlib
1 | sudo pip3 install matplotlib |
1 | import numpy as np |
运行结果
1 | #!/bin/python |
1 | from cycler import cycler |
1 | #### way 1 |
1 | pip3 install pandas |
1 | import pandas as pd |
1 | # 修改print时显示列行列数 |
1 | df = pd.read_csv('dataset.csv') |
1 | >> import pandas as pd |
1 | 转换为 np array |
1 | df.to_csv('output.cvs') |
1 | 描述数据 |
读操作
1 | 选取一列 |
转换操作
1 | 转换所有列 |
Drop 列
1 | # drop 有 nan 的列 |
排序
1 | df = df.sort_values(by=[<ClomunName>], ascending=False) |
过滤
1 | # loc |
连接
1 | # 用法 |
1 | 读取 Cell |
[toc]
xlrd
和xlwt
支持excel文件读写1 | s.values |
1 | # 读取csv文件,并转化为DataFrame |
1 | df.to_csv("output.csv", index=False) |
1 | print(data.columns) |
iloc
DF.clomun_name
: 通过列名选择1 | df['Column'].dtype |
1 | df['Column'][df['Column'].isna()] |
1 | df['Column'] = df['Column'].astype(str) |
1 | for c in df.loc[:, df.isna().any()]: |
1 | df.isna().sum() |
1 | df['Column'] = df['Column'].fillna(df['Column'].mean()) # 是用 Column 的平均值填充该列的 NaN 值 |
iloc
从DataFrame中选择数据
1 | df.iloc[:] # 选择所有行,所有列 |
示例程序
1 | ## With Series |
mean
计算均值
1 | import pandas as pd |
dropna
1 | DataFrame.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False) |
axis
0
: 行1
: 列how
any
: 只要有一个值为NA
,则删除该标签all
: 所有值均为NA
,则删除该标签thresh
NA
值数量大于该值,则保留该标签subset
array-like
)inplace
True
: 在原始数据集上进行操作,返回None
False
: 返回新的数据集,保持原始数据集不变1 | df.dorp('column-name', axis=1) |
1 | import pandas as pd |
1 | # dateframe |
1 | row.scores[0] |
1 | df_a.join(df_b, on=[{column}]) # 使用 on |
1 | df.filter((condition1) & (condition2)) |
1 | df.filter(col('name').contains('sun')) |
1 | df.filter(col('name') == "wii") |
1 | df.filter(col('name').isNull()) |
1 | df.filter(col('name').isin(["wii", "bovenson"])) |
1 | df_renamed = df.withColumnRenamed('name1', 'name2') |
1 | new_df = df.withColumn('After_discount', df.Course_Fees - df.Discount) |
1 | import pyspark.sql.functions as F |
1 | df.agg(max("age")).show() |
1 | df.toJson() |
1 | df.write.format('orc').save('/path/to/destination') |
文本文件
1 | df.coalesce(1).write.format("text").option("header", "false").mode("overwrite").save('/path/to/destination') |
1 | 代码 |
1 | 因为使用 from pyspark.sql.functions import * 导入,导致 abs 使用 from pyspark.sql.functions 内的函数 |
rdd.toDF()
时报错。
1 | from pyspark.sql import Row |
或者
1 | rdd.map(lambda x: (x, )).toDF() |
1 | var srcData = spark.read.json(srcPath) |
1 | spark.conf.set("spark.sql.caseSensitive", "true") |
1 | df.groupBy("column-name").count().show(false) |
1 | pip3 install pyspark |
1 | # 创建 spark session |
1 | // 创建 Spark Session |
1 | <dependency> |
1 | # 按行拼接 (列数不变) |
按行拼接
1 | %pyspark # zeppelin |
1 | ndf = df.groupBy('age').count() |
1 | # schema 1 |