0

Using some code I calculate some numbers. I store those numbers in a pandas dataframe namely data_nn. I have many such data_nn generated in a for loop.

While looping want to concatenate the data_nn with a dataframe namely data_all. Finally I would export the data_all to a csv file. But the concatenation fails.

Below my code. It gives an error: 'cannot concatenate object of type ""; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid'

How to resolve this?

import pandas as pd
import numpy as np

dat_nn={'File_name': 'AL902787D19_85_AC10_N0.09x0.07_Vcycle=1.5_Ncycle=0_vreset=0_1e-07s_Vg_max=2.5_Frd_swp_t=0.0003125_Rev_swp_t=0.0003125_T=25_It.txt',
 'Wafer': 'D19',
 'Dev_width': 0.09,
 'Dev_length': 0.07,
 'VCycle': 1.5,
 'NCycle': 0.0,
 'Vreset': 0.0,
 'Vg_max': 2.5,
 'Sweep t': 0.0003125,
 'Vt_up': 1.3732296825853794,
 'Vt_down': 1.416156137450131,
 'Hysteresis': -0.04292645486475166}

data_all = pd.DataFrame(data={'File_name':np.nan,'Wafer':np.nan,'Dev_width':np.nan,'Dev_length':np.nan,'VCycle':np.nan,'NCycle':np.nan,'Vreset':np.nan,'Vg_max':np.nan,'Sweep t':np.nan,'Vt_up':np.nan,'Vt_down':np.nan, 'Hysteresis':np.nan},index=[0])
data_nn=pd.DataFrame(data=dat_nn,index=[0])
data_all=pd.concat([data_all,dat_nn],axis=1)
1
  • You can also use merge: data_all.append(data_nn) Commented Sep 19, 2019 at 13:32

2 Answers 2

2

Looks like you have a typo in your last line:

data_all=pd.concat([data_all,dat_nn],axis=1)

should be

data_all=pd.concat([data_all,data_nn],axis=1)

I ran this and it worked for me.

Sign up to request clarification or add additional context in comments.

1 Comment

@Alam haha that happens to all of us! those are sometimes the hardest to find. if this was helpful, would you mind marking this as the accepted answer. I am trying to gain more reputation on the site.
1

You are passing the original dictionary dat_nn in pd.concat, instead of data_nn

Change it to:

data_all=pd.concat([data_all,data_nn],axis=1)

I would suggest using more unique variable names, like data_nn_dictionary and data_nn_dataframe.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.