Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
112 views
in Technique[技术] by (71.8m points)

python - data appending as dataframe in memory

I have data like this df:

,load,mem,Loc,Rem
0,1.0,7.48,6.7,pencil
1,1.0,8.020022,7.602671,book

df1:

0,log_no
1,1.2165430890794655

which I am appending at each iteration and it attaches like below with command

    df.to_csv(out_path,  mode='a', header=True)
    df1.to_csv(out_path,  mode='a', header=True)

and it results as csv below:

,load,mem,Loc,Rem
0,1.0,7.48,6.7,pencil
1,1.0,8.020022,7.602671,book
0,log_no
1,1.2165430890794655

Than, I have to import it again with

pd.read_csv()

I want to keep it appended as dataframe as df3 in memory to use it further instead of exporting and importing again. Is it possible? I tried to append several ways, but didn't succeed.

question from:https://stackoverflow.com/questions/65935690/data-appending-as-dataframe-in-memory

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Sure! Just use .append() method:

df3 = pd.DataFrame()

And then, inside loop:

df3 = df3.append(df)
df3 = df3.append(df1)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...