简体   繁体   English

如何将特定数据从一列移动到 Pandas 上的新列?

[英]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.

相关问题 如何将数据从一列移动到另一列? - How to move data from one column to another? 如何从一列中剪切数据并粘贴到 Python -> Pandas 中的新列中? - How to cut data from one column and paste into a new column in Python -> Pandas? 如何从一列中提取信息以在熊猫数据框中创建新列 - How to extract information from one column to create a new column in a pandas data frame 如何将数据从一列移动到另一列的行? - how to move data from one column to another column's row? 将数据从一列移动到另一列 - Move data from one column to another column 如何在大熊猫不相等的值上将数据从一列移动到另一列? - How do i move data from one column to another on values that aren't equal in pandas? 如何基于与熊猫匹配的列值将数据从一个数据帧移动到另一个数据帧? - How to move data from one dataframe to another based on matching column values with pandas? 根据熊猫的第四列将数据从一列移到另一列中的另一列 - Move data from one column to one of two others based on a fourth column in pandas 如何在 DataFrame 中创建新列并将 select 数据从第一列移动到新列 - How to create a new column in a DataFrame and move select data from the first column to the new column "多个groupby后如何将pandas数据从索引移动到列" - How to move pandas data from index to column after multiple groupby
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM