pandas
1.Series
1.Series is a one-dimensional labeled array
【Series 就是一个 一维 标签数组】
2.capable of holding any data type 【integers, strings, floating point numbers, Python objects, etc.).】
【存各种数据类型】
3.The axis labels are collectively referred to as the index
标签 就是索引 【可以用索引 取Series元素】
data = np.random.randint(1, 10, 3)
df = pd.DataFrame(data=data)
print(df)
print(df.index)
print(df.columns)
#2
data1 = np.random.randint(1, 10, 3)
df = pd.DataFrame(data=data1,index=["a","b","c"],columns=["num"])
print(df)
print(df.index)
print(df.columns)
2.df
1.DataFrame is a 2-dimensional labeled data structure with columns of potentially different types
【DataFrame 就是一个 二维 标签数组,多个不同数据类型的列】
【 index (row labels) and columns 】
【【DataFrame就是一个table 有行有列】
2.如何创建df :
Dict of 1D ndarrays, lists, dicts, or Series
2-D numpy.ndarray
Structured or record ndarray
A Series
Another DataFrame
【df 可以由多种数据 转化而来】
3.a dict of Series objects
df =》 table =》 有行有列
DataFrame = DataFrame【Series】
实例化:
df加载数据并拼接
# 1.加载数据
df = pd.read_csv(r"D:\data\emp.csv")
#数据拼接
df_union = pd.concat([df, df])
print(df_union.head(10))
#排序 orderby sort by
print("--" * 20)
print(df_fiter.head())
df_sort = df_fiter.sort_values(by=["sal"], ascending=False)
print("--" * 20)
print(df_sort.head())
df_sort1 = df_fiter.sort_values(by=["sal","ename"], ascending=[False,False])
print("--" * 20)
print(df_sort1.head())
#空值处理
df_etl = df_where.dropna(how='all') # where name is null all any
print("--" * 20)
print(df_etl.head())
df_etl = df_where.fillna(value=0) # select ifnull()
print("--" * 20)
print(df_etl.head())