簡體   English   中英

當同一行中的數據添加到另一列時,計算一行的列值

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

我在python中有一個大熊貓數據框。 我有7列原始數據,它們會定期一次全部更新,並且每次將新數據添加到第1-7列的底部時,我都需要更新其他84列的新行中的值。 我想這樣做,而不必重新計算整個其他84列的所有值。 因為這些列中有數百萬行。

在主數據幀上進行第一次計算之后,請嘗試分別對新數據進行計算,然后在最后合並它們(前提是在合並之前,它們都具有相同的列)。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM