python-pandas模块2-基本数据类型2
2020-08-21 20:18
351 查看
pandas模块-基本数据类型2
导入模块
import pandas as pd import numpy as np from pandas import Series,DataFrame
3.通过字典中包含字典创建个DataFrame
创建字典并转换为DataFrame
dict_city={ 'shanghai':{2019:54000,2020:56000}, 'beijing':{2018:66666,2019:77777} } df_city=DataFrame(dict_city) df_city
(1)增加数据
df.insert(loc, column, value, allow_duplicates=False)
loc:索引位
column:列名称
value:值
allow_duplicates : 是否允许重复
新增深圳的数据到df_city中
df_city.insert(2,'shenzhen',[60000,70000,80000],allow_duplicates=True) df_city
4.给行列取个名称
df_city.index.name='年份' df_city.columns.name='城市' df_city
5.可以单独创建索引对象,用来创建数据
pd.Index()
方法1
s=Series([1,2,3,4],index=['a','b','c','d']) s.index.name='haha' s
方法2
s2=Series([1,2,3,4],index=pd.Index(['a','b','c','d'],name='haha')) s2
6.创建一个用日期做索引的数
pd.date_rang(start,end,periods)
start;开始日期
end:结束日期
periods:周期间隔
相关文章推荐
- Python数据挖掘学习02--numpy和pandas模块基本使用
- Python数据分析模块 | pandas做数据分析(一):基本数据对象
- Python学习教程:基本数据类型
- 1.1.5 python基本数据类型之集合
- python如何读取excel表格的数据呢?xlrd pandas模块
- 数据挖掘-Python基本模块
- Python学习笔记(4)-基本的数据类型
- python基本数据类型——tuple
- Python 基本数据类型之【格式化问题】
- python基本数据类型——int
- DAY3:Python基本数据类型,time库
- Python3 基本数据类型
- python02-运算符和基本数据类型
- Python学习笔记之基本数据类型
- Python语法 之 基本数据类型
- Python3 基本数据类型
- Python数据挖掘学习03--pandas模块数据的导入实战
- 利用Python进行数据分析(六)之pandas基本功能
- python基本语法——组合数据类型
- python基础教程之基本内置数据类型介绍