python,pandas, DataFrame数据获取方式
一、创建DataFrame
df=pd.DataFrame(np.arange(,).reshape(,))
my_col=dict(zip(range(),['A','B','C']))
df.rename(columns=my_col,inplace=True)
print(df)
print(type(df)) 结果为:
A B C <class 'pandas.core.frame.DataFrame'>
一、at和iat的用法
at和iat,可选择指定行、指定列的单个元素。
1.at的用法
a=df.at[,'A']
print(a)
print(type(a)) 结果为: <class 'numpy.int32'>
2.iat的用法
a=df.iat[,]
print(a)
print(type(a))
结果为: <class 'numpy.int32'>
一、loc和iloc的用法
loc和iloc,可选择指定行、指定列或者某个区域的多个元素。
1.loc的用法
a=df.loc[,'A']
print(a)
print(type(a))
结果为: <class 'numpy.int32'> a=df.loc[:,'A']
print(a)
print(type(a))
结果为: <class 'pandas.core.series.Series'> a=df.loc[:,:]
print(a)
print(type(a))
结果为:
A B C <class 'pandas.core.frame.DataFrame'> a=df.loc[:,:]
print(a)
print(type(a))
结果为:
A B C <class 'pandas.core.frame.DataFrame'>
2.iloc的用法
a=df.iloc[,]
print(a)
print(type(a))
结果为: <class 'numpy.int32'> a=df.iloc[:,]
print(a)
print(type(a))
结果为: <class 'pandas.core.series.Series'> a=df.iloc[:,:]
print(a)
print(type(a))
结果为:
A B C <class 'pandas.core.frame.DataFrame'> a=df.iloc[:,:]
print(a)
print(type(a))
结果为:
A B C <class 'pandas.core.frame.DataFrame'>
四、df的用法
df,要么选择指定列的元素,要么选择指定行的元素,要么通过条件判断选择指定区域的元素。
a=df['A']
print(a)
print(type(a))
结果为: <class 'pandas.core.series.Series'> a=df[['A','B']]
print(a)
print(type(a))
结果为:
A B <class 'pandas.core.frame.DataFrame'> a=df[df['A']>=]
print(a)
print(type(a))
结果为:
A B C <class 'pandas.core.frame.DataFrame'> a=df[:]
print(a)
print(type(a))
结果为:
A B C <class 'pandas.core.frame.DataFrame'>
python,pandas, DataFrame数据获取方式的更多相关文章
- Python pandas DataFrame操作
1. 从字典创建Dataframe >>> import pandas as pd >>> dict1 = {'col1':[1,2,5,7],'col2':['a ...
- Python pandas.DataFrame调整列顺序及修改index名
1. 从字典创建DataFrame >>> import pandas >>> dict_a = {'],'mark_date':['2017-03-07','20 ...
- Python Pandas -- DataFrame
pandas.DataFrame class pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False) ...
- python pandas.DataFrame选取、修改数据最好用.loc,.iloc,.ix
先手工生出一个数据框吧 import numpy as np import pandas as pd df = pd.DataFrame(np.arange(0,60,2).reshape(10,3) ...
- python pandas dataframe to_sql方法error及其解决
今天遇到了一个问题,很是奇怪,自己也想了一个另类的方法将其解决了,现在将详细过程经过记录如下: 我在处理完一个dataframe之后,需要将其写回到数据库.这个dataframe比较大,共有53列,7 ...
- python pandas.DataFrame.append
1.使用append首先要注意的是,你要合并两个DataFrame的columns即列名是否是相同的,不相同的就会报错. 2.我们会发现DataFrame的列名是不能够重复的,而行名(index)是可 ...
- python pandas dataframe 操作记录
从数据看select出数据后如何转换为dataframe df = DataFrame(cur.fetchall()) 如何更改列名,选取列,进行groupby操作 df.columns = ['me ...
- python pandas.DataFrame .loc,.iloc,.ix 用法
refer to: http://www.cnblogs.com/harvey888/p/6006200.html
- python pandas dataframe 读取和写入Oracle
1.代码:主要写入时表要为小写,否则报错 Could not reflect: requested table(s) not available in Engine from sqlalchemy i ...
随机推荐
- pandas dataframe取差集:删掉已存在的数据,保留未插入的数据
适用场景: 插入数据到mysql中,中途中断,导致部分数据未插入成功.避免下次插入时插入了重复的数据. 思路: 1.读取已插入的数据, 2.读取全部数据(包含已插入和未插入的), 3.将已插入的数据添 ...
- Redis高级用法
第一章 redis初识 1.1 Redis是什么 介绍 开源:早起版本2w3千行 基于键值对的存储系统:字典形式 多种数据结构:字符串,hash,列表,集合,有序集合 高性能,功能丰富 那些公司在用 ...
- [极客大挑战 2019]FinalSQL
0x00 知识点 盲注 0x01 解题 根据题目提示盲注,随便点几下找到注入点 发现我们输入^符号成功跳转页面,证明存在注入 1^(ord(substr((select(group_concat(sc ...
- Sequence Models Week 1 Improvise a Jazz Solo with an LSTM Network
Improvise a Jazz Solo with an LSTM Network Welcome to your final programming assignment of this week ...
- Q7:Reverse Integer
7. Reverse Integer 官方的链接:7. Reverse Integer Description : Given a 32-bit signed integer, reverse dig ...
- .NET 软件下面win10自动启动配置
1.设置所有用户登录都能启动,打开文件夹 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp 2.给要启动的应用程序创建快捷方式, ...
- JKS not Found
近期使用Spring Boot开发微信验证的时候, 在获取token时,Idea老是提示Jks not found,网上找资料,都说是SSL的问题 实际解决方法: 重装JDK,将JDK重装之后,运行正 ...
- POJ 1141 经典DP 轨迹打印
又几天没写博客了,大二的生活实在好忙碌啊,开了五门专业课,每周都是实验啊实验啊实验啊....我说要本月刷够60题,但好像完不成了,也就每天1题的样子.如今写动规还是挺有条理的,包括这道需要打印轨迹,其 ...
- Dynamics CRM - 在 C# Plugin 里以 System Administrator 权限来更新 Entity
场景说明: 1.在使用 CRM 系统时,经常会有需要在某个 Entity 下对其他 Entity 的 Record 进行更新,或者在 post 中对自身进行更新,这里就需要用到 SDK 上的 upda ...
- runlevel 运行级别
linux启动过程 关于Ubuntu 12.04修改默认运行级别,启动字符界面的个人理解 网上通常的做法是:(亲自试验,不管用),如果想直接操作请看绿色字体部分 (1)第一种方法: 由于Red ...