Pandas
冰冷的希望
坚持记录,相互帮助,一起进步
展开
-
【Pandas】merge合并
1.on属性import pandas as pddf1 = pd.DataFrame({"a": ["A1", "A2", "A3"], "c": ["C1", "C2", "C3"], "b": ["B1", "B2", "B3"],})df2 = pd.DataFrame({"d": ["D1", "D2...原创 2020-03-08 17:35:33 · 275 阅读 · 0 评论 -
【Pandas】合并DataFrame
1.创建DataFramedf1 = pd.DataFrame(np.arange(0, 12).reshape(3, 4), columns=["A", "B", "C", "D"])df2 = pd.DataFrame(np.arange(12, 24).reshape(3, 4), columns=["A", "B", "C", "D"])2.直接合并# pd.concat(),a...原创 2020-03-08 17:04:52 · 245 阅读 · 0 评论 -
【Pandas】读取和保存文件
1.读取文件Pandas可以读取xlsx、json、csv、sql等多种文件格式import pandas as pd# 读取文件file = pd.read_excel("test.xlsx", encoding="utf-8") # 需要安装xlrd模块# file = pd.read_csv()# file = pd.read_json()# file = pd.read_...原创 2020-03-08 16:11:23 · 2213 阅读 · 0 评论 -
【Pandas】检查是否有空值、处理空值
1.创建有空值的DataFrameimport numpy as npimport pandas as pddates = pd.date_range("20200307", periods=4)df1 = pd.DataFrame(np.arange(12).reshape(4, 3), index=dates, columns=["A", "B", "C"])df2 = pd.Da...原创 2020-03-08 15:39:14 · 24961 阅读 · 1 评论 -
【Pandas】给DataFrame赋值、增删行或列
1.创建DataFrameimport numpy as npimport pandas as pddates = pd.date_range("20200301", periods=6)df2 = pd.DataFrame(np.arange(24).reshape((6, 4)), index=dates, columns=["A", "B", "C", "D"])print(df...原创 2020-03-05 18:07:52 · 6022 阅读 · 0 评论 -
【Pandas】选择数据
1.创建一个DataFrameimport numpy as npimport pandas as pddates = pd.date_range("20200301", periods=6)df1 = pd.DataFrame(np.arange(24).reshape((6, 4)), index=dates, columns=["A", "B", "C", "D"])print(...原创 2020-03-03 19:02:18 · 507 阅读 · 0 评论 -
【Pandas】创建Series和DataFrame
1、SeriesSeries可以看成是一个有序的字典import pandas as pds1 = pd.Series([1, 2, 3, 4]) # 简单创建Series,使用默认索引(从0开始的数字)print(s1)s2 = pd.Series([1, 2, 3, 4], index=['b', 'a', 'c', 'd']) # 创建Series时指定索引s3 = pd....原创 2020-03-02 22:26:53 · 832 阅读 · 0 评论