0

I am trying to write in Python a code which allows me to have a "big" Dataframe (using Pandas) in an text file (constituted from 8 array). My problem is that if the DataFrame has more than 60 columns, it´s not showed completely and is also with continuity points in the text file. I added a screen shot.

Here is my code:

TemperatureStagnation = []
PressureStagnation = []
Pressure = []
AlphaAngle = []
GammaAnlge = []
TurbulentDissipationRate = []
TurbulentEnergyKinketik = []

for i in range(1,len(Machnumber)+1):
  Tt = 240 #in K - Isotherm Profile
  p = 36630 #in Pa - isobar 
  pt = p * (1+((kappa-1)/2)*Machnumber[i-1]**2)**(kappa/(kappa-1)) #isentropic Flow relation
  Alpha = 0.000 #No deviation
  Gamma = 0.000 #No deviation
  TDR = 0.000 #Zero Turbulent Dissipation Rate
  TEK = 0.000 #Zero Turbulent Energy Kinetic
  
  TemperatureStagnation.append(Tt)
  PressureStagnation.append(pt)
  Pressure.append(p)
  AlphaAngle.append(Alpha)
  GammaAnlge.append(Gamma)
  TurbulentDissipationRate.append(TDR)
  TurbulentEnergyKinketik.append(TEK)
  
Header = "TRACE_Input_Wall"
Input = pd.DataFrame({'Rr':Rr,'Ma':Machnumber,'Tt':TemperatureStagnation,'pt':PressureStagnation,'p':Pressure,'Alpha':AlphaAngle,'Gamma':GammaAnlge,'TDR':TurbulentDissipationRate,'TEK':TurbulentEnergyKinketik}) 
print (Input)
f= open("TRACE_Input_Wall.txt","w+")
file = open("TRACE_Input_Wall.txt","r+")
file.truncate(0)
file.close()
print (Header,file=open("TRACE_Input_Profiles_Mourad.txt", "a"))
print (Input,file=open("TRACE_Input_Profiles_Mourad.txt", "a"))
print ("Output successful!")     

Anyone has a better idea? (pandas and numpy are already imported in my orenter image description hereiginal code.)

1 Answers1

0

As Felício commented, you could just use

np.savetxt('/path/to/file.txt', Input.values)

for saving the data in a txt file (for more info see numpy.savetxt.html). Definitely working for >60 columns, but the header needs to be added separately.

Alternatively you could use

Input.to_csv('/path/to/file.csv')

to save the data in a csv file (see pandas.DataFrame.to_csv.html for more options).

This question might help, if you want to see all data frame columns in Spyder: python-spyder-show-all-colums-of-a-pandas-dataframe

rosa b.
  • 1,759
  • 2
  • 15
  • 18