在Pandas上导入文本文件时出现问题。当我在文本中打开文件时,列没有问题,但是当我用Pandas打开它时,我不能拆分列,并且Jupiter-notebook将其识别为一列。我想有三列标题分别是'Z‘、'H’和‘err’。what will give me when I open the saved file
data= np.genfromtxt('/path/hubel.dat')
df=pd.DataFrame(data)
df.columns= ['Z', 'H', 'err']
df_groupby_err=df.groupby("err")
for err, H in df.groupby("err"):
if err<20:
print( )
print( H )
print( )
f=open("hubble_error_edited-2.txt", "w")
for err, H in df.groupby("err"):
if err<20:
f.write("\n"+str(H)+""+ "\n")
f.close()
data= pd.read_csv("/path/hubble_error_edited-2.txt" )
发布于 2021-07-16 13:46:26
您可以尝试在separator
参数中添加blank space
:
data= pd.read_csv("/path/hubble_error_edited-2.txt", sep=' ')
https://stackoverflow.com/questions/68409792
复制相似问题