CuriousDataScientist
CuriousDataScientist

Reputation: 43

Dynamically separate and convert SAP txt file of mixed datatypes to readable and non-scientific notation

I got a Dataframe of kind as .txt-format out of SAP. There's currently no option to export as .csv or any other data format. The .txt file contains multiple data frames in one file. SAP has a special format - I don't know if Python has a specific method to convert this data easily to readable numbers. Furthermore all tables have a dynamic length (= count of rows). Below an extract of the dataframe:

TABLE  PRODUCT_DATA
RESORC STORA       CAPA      PROF
STRING REAL        REAL      REAL
ProdA  0.0000E+1   0.005E+1  4215451.56
ProdB  0.0000E+1   0.002E+1  000000
//
TABLE ITEM_DATA
ITEM  STORA       CAPA       PROF
STRING REAL        REAL      REAL
ITEMA  0.0000E+1   0.005E+1  4215451.56
ITEMB  0.0000E+1   0.002E+1  000000
ITEMC  2.0000E+1   0.000E+1  245161
//

Desired Result: Is there a simple method to simply convert these data frames to non-scientific notation as these are mixed dataframes?

Tries: .astype(float) and float() are currently not working in my coding as these are mixed types. Are not deliverring the expected result 

Questions: Do you know how I can separate all dataframes based on the beginning TABLE followed by the name and the end marks '//' while converting the scientific-SAP-output to float numbers. Does SAP have a special conversion rate?

Thanks in advance for your help.

Upvotes: 1

Views: 239

Answers (1)

CuriousDataScientist
CuriousDataScientist

Reputation: 43

sure! :) I mainly used a for-loop to convert each col in dataframe to a float number:

for col in  df_loc.columns[2:]:
        df_loc[col] = pd.to_numeric(df_loc[col], errors='coerce')
        return df_loc

Upvotes: 1

Related Questions