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