简体   繁体   English

按列从另一个DataFrame创建一个DataFrame

[英]Create a DataFrame from another DataFrame by column

I would like to create a data frame from another data frame - but I want to do it by specifying the coordinates. 我想从另一个数据框创建一个数据框-但我想通过指定坐标来做到这一点。 In this case I want the new DataFrame to contain only the first column. 在这种情况下,我希望新的DataFrame仅包含第一列。

The following is correct in that it works: 以下是正确的,因为它可以工作:

US_effective_rate = US_forward_rates.iloc[:,1].copy()
US_effective_rate = US_effective_rate.to_frame()

I was wondering if there's a better implementation, possibly using .filter()? 我想知道是否有更好的实现,可能使用.filter()?

there are similar questions but they reference column names, not coordinates. 有类似的问题,但它们引用的是列名,而不是坐标。

thank you very much. 非常感谢你。

PS: I actually just want the dimensions and index from the first frame, going to overwrite the actual data. PS:实际上,我只想要第一帧的尺寸和索引,以覆盖实际数据。 Any chance I could do THAT in one hit? 我有机会一击就做到吗?

是的,您只需添加[]

US_forward_rates.iloc[:,[1]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PySpark DataFrame - 从另一个 dataframe 创建一个列 - PySpark DataFrame - Create a column from another dataframe 无法从另一个 dataframe 在 dataframe 中创建列 - Unable to create a column in a dataframe from another dataframe 从另一个Dataframe创建Dataframe - Create Dataframe from another Dataframe 如何通过拆分从数据框中的另一列创建 Pandas 数据框? - How to create a Pandas dataframe from another column in a dataframe by splitting it? Python 3.x-使用来自另一个数据框的列名创建数据框 - Python 3.x - Create dataframe with column names from another dataframe 如何从另一个用逗号“,”连接的数据框中的列创建数据框 - How to create a dataframe from a column in another dataframe that concat by comma ',' 使用来自另一个数据帧的 if 条件在 Pandas 数据帧中创建一个新列 - create a new column in pandas dataframe using if condition from another dataframe 根据来自另一个数据框的 2 个条件创建新的数据框列 - Create new dataframe column based on 2 criteria from another dataframe 检查一个数据框中的值是否存在于另一个数据框中并创建列 - Check if value from one dataframe exists in another dataframe and create column 将数据框中的列的行创建为另一个数据框中的列 - Create rows of a column in a dataframe as a column in another dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM