简体   繁体   中英

Adding a name (string) column to an existing pandas DF

I have an array(of float data type) from a FITS file of (1, 5000) dimension. I have created a pandas DF from it so that I can export it as a csv later. 来自数据的数据帧 . However I am trying to add an extra column in the beginning (ie at [0,0]) with the name of the file ie 'FSC0029m4226', a string. So that I can use the first column as a class and the remaining 5000 columns as features for ML applications. Also when I add rows in future, the first column can then help in identifying the candidates. Is there any other method than using pd.DataFframe for this ?

This is what I have tried :

A = 'FSC0029m4226'
FSC0029m4226.insert(loc=0,column = 'Name',value = A)

But keep getting errors with the bottom line being,

ValueError: Big-endian buffer not supported on little-endian compiler

However if I try with an artificial sample data it works :

xx = np.linspace(0,59.05,100)
print xx.dtype
xxx =np.reshape(xx,(1,100))
x4= pd.DataFrame(xxx)
x4.insert(loc=0,column = 'Name',value = A)
print x4

在此处输入图片说明

FSC0029m4226 = pd.DataFrame(np.array(FSC0029m4226).byteswap().newbyteorder())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM