简体   繁体   中英

How can I convert a single row DataFrame to string in Python?

I have a Pandas DataFrame with only one row (it's been filtered prior). For AutoML Tables, I need the inputs in the format shown below - does anyone know the best way to achieve this?

Pandas Dataframe (Sample):

Time                 Open     High     Low      Close       Volume
2021-02-23 19:30:00  1.21567  1.21576  1.21483  1.21484     943

AutoML Required Format:

inputs = {'AverageTrueRange': 0.000697, 'BB_Width': 0.001842, 'CandleRange': 0.00074, 'Close': 1.17512, 'EMA_Gap': -0.00168, 'EntryTime': "2017-11-20 07:30:00", 'MACD_HIST': 0.000329, 'ModFisher': 2.276938, 'ModFisher14': 2.393746, 'PosWithinClose': 0.32, 'PosWithinLowHigh': 0.99, 'RollingVoli': 0.000579, 'RSI': 59.609776, 'Signal': "BEAR SIGNAL", 'Stoch14': 0.991736, 'Volume': 668}

What's the best way to transform the DataFrame into the format I need? It looks kind of dictionary like but there are some discrepancies.

Any help would be much appreciated:)

data = [ { "Time": "2021-02-23 19:30:00", "Open": 1.21567, "High": 1.21576, "Low": 1.21483, "Close": 1.21484, "Volume": 943 } ]
df = pd.DataFrame(data)
inputs = df.to_dict('records')[0]

Result:

{'Close': 1.21484, 'High': 1.21576, 'Low': 1.21483, 'Open': 1.21567, 'Time': '2021-02-23 19:30:00', 'Volume': 943}

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