[英]How to move specific data from one column to a new column on Pandas?
I have a set of data with 2 columns: Column1 = Hex Code and Column2= Current (A).我有一组包含 2 列的数据:Column1 = Hex Code 和 Column2 = Current (A)。
The data in Column1 is Hex Code, 27 different codes which repeats and for each Hex Code have Current (A) value on Column2. Column1 中的数据是十六进制代码,27 个不同的代码重复,每个十六进制代码在 Column2 上都有当前 (A) 值。
I want to pick a set of 27 data points from Column1 & Column2 and place them into Coulmn3 & Column4.我想从 Column1 和 Column2 中选择一组 27 个数据点并将它们放入 Coulmn3 和 Column4 中。
Can someone help me to achieve this?有人可以帮助我实现这一目标吗?
This is how the initial data looks这是初始数据的样子
This is how i would like the data to be arranged这就是我希望数据的排列方式
I am going tho show you my code.我将向您展示我的代码。 But I want to tell that you can not have repeating columns names.但我想告诉你,你不能有重复的列名。 We suppose data is the name of your original dataset:我们假设 data 是您的原始数据集的名称:
import pandas as pd
col_name1=data.columns.values[0]
col_name2=data.columns.values[1]
two_columns = data[[col_name1,col_name2]][0:27].values
two_columns = pd.DataFrame(two_columns,columns=[col_name1+'_1',col_name2+'_2'])
df = data.iloc[0:27,:]
df = df.join(two_columns)
print(df)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.