简体   繁体   English

当同一行中的数据添加到另一列时,计算一行的列值

[英]calculate value of a column for a row when data in same row is added to another column

I have a large pandas data frame in python. 我在python中有一个大熊猫数据框。 I have seven columns of raw data that get updated all at once on a periodic basis, and I need to update the values in the new rows of the 84 other columns every time new data is added to the bottom of columns 1-7. 我有7列原始数据,它们会定期一次全部更新,并且每次将新数据添加到第1-7列的底部时,我都需要更新其他84列的新行中的值。 I would like to do this without having to recalculate all the values of the entire 84 other columns. 我想这样做,而不必重新计算整个其他84列的所有值。 as there are millions of rows in these columns. 因为这些列中有数百万行。

After doing the first calculation on the main dataframe, try doing the calculation for new data separately then concat them at the end (provided both have the same columns before concatenation). 在主数据帧上进行第一次计算之后,请尝试分别对新数据进行计算,然后在最后合并它们(前提是在合并之前,它们都具有相同的列)。

import pandas as pd

columns = ['c1','c2','c3','c4','c5','c6','c7']

main = pd.read_csv('file.csv', names=columns)
# ... do your calculation

new = pd.read_csv('new_file.csv', names=columns)
# ... do your calculation

all = pd.concat([main, new])

# if you need to reset the index, use the following line instead:
# all = pd.concat([main, new], ignore_index=True)

暂无
暂无

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

相关问题 逐行计算列的聚合值 - Calculate aggregate value of column row by row Pandas Dataframes:列表中列的值是否嵌套在同一行的另一列中? - Pandas Dataframes: is the value of a column in a list nested in another column, same row? Label 基于另一列(同一行)的值的列 pandas dataframe - Label a column based on the value of another column (same row) in pandas dataframe pandas:根据另一列中的值计算每一行的jaccard相似度 - pandas:calculate jaccard similarity for every row based on the value in another column 当同一行中的另一列为NaN时,如何从熊猫数据框中选择特定的列值? - How to select a particular column value from a pandas dataframe when another column in the same row is NaN? 根据Pandas中第二列的条件,用另一行的同一列的值填充特定行的列中的值 - Fill values in a column of a particular row with the value of same column from another row based on a condition on second column in Pandas 如果值介于区间之间,则选择另一列中同一行上的值 - If a value is between an interval, select the value on the same row in another column 根据同一行中另一列的值填充缺失值 - Fill missing value based on value from another column in the same row 用另一个值替换列和行 - replacing column and row with another value (PRAW)从评论中获取一个值,然后用另一列的数据作为答复,该数据与第一条数据在同一行 - (PRAW) Get a value from a comment, then reply with another column's data, that's on the same row as the first piece of data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM