pandas合并concatmerge和plot画图

3.6,3.7pandas合并concat&merge

头文件:

import pandas as pd
import numpy as np

concat基础合并用法

df1= pd.DataFrame(np.ones((3,4))*0,columns = ['a','b','c','d'])
df2= pd.DataFrame(np.ones((3,4))*1,columns = ['a','b','c','d'])
df3= pd.DataFrame(np.ones((3,4))*2,columns = ['a','b','c','d'])res = pd.concat([df1,df2,df3],axis=0,ignore_index=True)   #axis=0 竖向合并  ignore_index是让索引重新排序df1= pd.DataFrame(np.ones((3,4))*0,columns = ['a','b','c','d'])
df2= pd.DataFrame(np.ones((3,4))*1,columns = ['b','c','d','e'])

concat中join用法

#join='outer'可以对标签不一样的部分用NAN进行填充
#join = 'inter'时对标签不一样的部分去掉
res = pd.concat([df1,df2],join='outer',ignore_index=True)

join_axes (新版本删除了)

join_axes= [df1.index]设置合并后按照df1的索引进行保留

# res = pd.concat([df1,df2],axis=1,join_axes = [df1.index])

append添加数据

#添加整个数据
df1= pd.DataFrame(np.ones((3,4))*0,columns = ['a','b','c','d'])
df2= pd.DataFrame(np.ones((3,4))*1,columns = ['a','b','c','d'])
df3= pd.DataFrame(np.ones((3,4))*2,columns = ['a','b','c','d'])
res = df1.append([df2,df3],ignore_index=True)   #上下结合#添加一行数据
s1 = pd.Series([1,2,3,4],index=['a','b','c','d'])
res = df1.append(s1,ignore_index=True)

merge按照key合并

left = pd.DataFrame({'key':['K0','K1','K2','K3'],'A':['A0','A1','A2','A3'],'B':['B0','B1','B2','B3']
})
right = pd.DataFrame({'key':['K0','K1','K2','K3'],'C':['C0','C1','C2','C3'],'D':['D0','D1','D2','D3']
})
#按照key合并
res = pd.merge(left,right,on='key')
print(res)

merge考虑两个key,根据index进行数据合并

#若考虑两个key,根据index进行数据合并
res = pd.merge(left,right,on=['key1','ke2'])    #默认是'inner':只考虑相同部分
res = pd.merge(left,right,on=['key1','ke2'],how='outer')    #outer:全部考虑,不存在的用nan填充

merge中indicator

indicator=True时,能展示合并后,哪部分是有某标签数据,哪部分是没有该标签数据的

res = pd.merge(left,right,on=['key1','ke2'],how='outer',indicator=True)

merge中left_index和right_index

根据数据索引进行结合
res = pd.merge(left,right,left_index=True,right_index=True,how=‘outer’)

merge中suffixes

suffixes来区分标签相同但是数值不同的数据

boys = pd.DataFrame({'K':['K0','K1','K2'],'age':[1,2,3]})
girls = pd.DataFrame({'K':['K0','K1','K2'],'age':[4,5,6]})res = pd.merge(boys,girls,on='K',suffixes=['_boy','_girl'],how='inner')

3.8pandas plot画图

头文件:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

Series的数据(类似数组)

data = pd.Series(np.random.randn(1000),index=np.arange(1000))
data = data.cumsum()    #对生成的1000个数据进行累加
data.plot()
plt.show()

DataFrame数据(类似矩阵)

折线图:

data = pd.DataFrame(np.random.randn(1000,4),index = np.arange(1000),columns = list("ABCD"))
data = data.cumsum()
data.plot()
plt.show()

散点图

ax = data.plot.scatter(x='A',y='B',color='DarkBlue',label = 'Class 1')
data.plot.scatter(x = 'A',y = 'C',color = 'DarkGreen',label='Class 2',ax=ax)
plt.show()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389330.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Android跳转WIFI界面的四种方式

第一种 Intent intent new Intent(); intent.setAction("android.net.wifi.PICK_WIFI_NETWORK"); startActivity(intent); 第二种 startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS)); 第三种 Intent i new Intent(); if(android.os.Buil…

PS抠发丝技巧 「选择并遮住…」

PS抠发丝技巧 「选择并遮住…」 现在的海报设计,大多数都有模特MM,然而MM的头发实用太多了,有的还飘起来…… 对于设计师(特别是淘宝美工)没有一个强大、快速、实用的抠发丝技巧真的混不去哦。而PS CC 2017版本开始,就有了一个强大…

covid 19如何重塑美国科技公司的工作文化

未来 , 技术 , 观点 (Future, Technology, Opinion) Who would have thought that a single virus would take down the whole world and make us stay inside our homes? A pandemic wave that has altered our lives in such a way that no human (bi…

Symbol Mc1000 Text文本阅读器整体代码

using System; using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Collections;using System.IO;namespace text{ /// <summary> /// Form1 的摘要说明。 /// </summary> public c…

python生日悖论分析_生日悖论

python生日悖论分析If you have a group of people in a room, how many do you need to for it to be more likely than not, that two or more will have the same birthday?如果您在一个房间里有一群人&#xff0c;那么您需要多少个才能使两个或两个以上的人有相同的生日&a…

统计0-n数字中出现k的次数

/*** 统计0-n数字中出现k的次数&#xff0c;其中k范围为0-9 */ public static int countOne(int k, int n) {if (k > n) {return 0;}int sum 0;int right 0;for (int i 0; n > 0; i) {int last n % 10;sum last * i * (int) Math.pow(10, i - 1);if (k 0) {sum - (…

房价预测 search Search 中对数据预处理的学习

对于缺失的数据&#xff1a; 我们对连续数值的特征做标准化&#xff08;standardization&#xff09;&#xff1a;设该特征在整个数据集上的均值为 μ &#xff0c;标准差为 σ 。那么&#xff0c;我们可以将该特征的每个值先减去 μ 再除以 σ 得到标准化后的每个特征值。对于…

3.6.1.非阻塞IO

本节讲解什么是非阻塞IO&#xff0c;如何将文件描述符修改为非阻塞式 3.6.1.1、阻塞与非阻塞 &#xff08;1&#xff09;阻塞是指函数调用会被阻塞。本质是当前进程调用了函数&#xff0c;进入内核里面去后&#xff0c;因为当前进程的执行条件不满足&#xff0c;内核无法里面完…

rstudio 管道符号_R中的管道指南

rstudio 管道符号R基础知识 (R Fundamentals) Data analysis often involves many steps. A typical journey from raw data to results might involve filtering cases, transforming values, summarising data, and then running a statistical test. But how can we link al…

蒙特卡洛模拟预测股票_使用蒙特卡洛模拟来预测极端天气事件

蒙特卡洛模拟预测股票In a previous article, I outlined the limitations of conventional time series models such as ARIMA when it comes to forecasting extreme temperature values, which in and of themselves are outliers in the time series.在上一篇文章中 &#…

iOS之UITraitCollection

UITraitCollection 为表征 size class 而生&#xff0c;用来区分设备。你可以在它身上获取到足以区分所有设备的特征。 UITraitEnvironment 协议、UIContentContainer 协议 UIViewController 遵循了这两个协议&#xff0c;用来监听和设置 traitCollection 的变化。 protocol UI…

直方图绘制与直方图均衡化实现

一&#xff0c;直方图的绘制 1.直方图的概念&#xff1a; 在图像处理中&#xff0c;经常用到直方图&#xff0c;如颜色直方图、灰度直方图等。 图像的灰度直方图就描述了图像中灰度分布情况&#xff0c;能够很直观的展示出图像中各个灰度级所 占的多少。 图像的灰度直方图是灰…

eclipse警告与报错的修复

1.关闭所有eclipse校验 windows->perference->validation disable all 2.Access restriction: The constructor BASE64Decoder() is not API (restriction on required library C:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar) 在builde path 移除jre&#xff0c;再…

时间序列因果关系_分析具有因果关系的时间序列干预:货币波动

时间序列因果关系When examining a time series, it is quite common to have an intervention influence that series at a particular point.在检查时间序列时&#xff0c;在特定时间点对该序列产生干预影响是很常见的。 Some examples of this could be:例如&#xff1a; …

微生物 研究_微生物监测如何工作,为何如此重要

微生物 研究Background背景 While a New York Subway station is bustling with swarms of businessmen, students, artists, and millions of other city-goers every day, its floors, railings, stairways, toilets, walls, kiosks, and benches are teeming with non-huma…

Linux shell 脚本SDK 打包实践, 收集assets和apk, 上传FTP

2019独角兽企业重金招聘Python工程师标准>>> git config user.name "jenkins" git config user.email "jenkinsgerrit.XXX.net" cp $JENKINS_HOME/maven.properties $WORKSPACE cp $JENKINS_HOME/maven.properties $WORKSPACE/app cp $JENKINS_…

opencv:卷积涉及的基础概念,Sobel边缘检测代码实现及卷积填充模式

具体参考我的另一篇文章&#xff1a; opencv:卷积涉及的基础概念&#xff0c;Sobel边缘检测代码实现及Same&#xff08;相同&#xff09;填充与Vaild&#xff08;有效&#xff09;填充 这里是对这一篇文章的补充&#xff01; 卷积—三种填充模式 橙色部分为image, 蓝色部分为…

怎么查这个文件在linux下的哪个目录

因为要装pl/sql所以要查找tnsnames.ora文件。。看看怎么查这个文件在linux下的哪个目录 find / -name tnsnames.ora 查到&#xff1a; /opt/app/oracle/product/10.2/network/admin/tnsnames.ora/opt/app/oracle/product/10.2/network/admin/samples/tnsnames.ora 还可以用loca…

无法从套接字中获取更多数据_数据科学中应引起更多关注的一个组成部分

无法从套接字中获取更多数据介绍 (Introduction) Data science, machine learning, artificial intelligence, those terms are all over the news. They get everyone excited with the promises of automation, new savings or higher earnings, new features, markets or te…