写Excel操作

    1. import pandas as pd
    2. players = [{'dailyWinners': 3, 'dailyFreePlayed': 2, 'user': 'Player1', 'bank': 0.06},
    3. {'dailyWinners': 3, 'dailyFreePlayed': 2, 'user': 'Player2', 'bank': 4.0},
    4. {'dailyWinners': 1, 'dailyFree': 2, 'user': 'Player3', 'bank': 3.1},
    5. {'dailyWinners': 3, 'dailyFree': 2, 'user': 'Player4', 'bank': 0.32}]
    6. df = pd.DataFrame.from_dict(players)
    7. print (df)
    8. df.to_excel('players.xlsx')

    读Excel操作

    1. import pandas as pd
    2. df = pd.read_excel('players.xlsx', index_col=0)
    3. print('Excel Data to Dict:', df.to_dict(orient='record'))
    4. print('----------------------------------------------------------------------')
    5. print('Excel Data to JSON:', df.to_json(orient='records'))
    6. print('-----------------------------------------------------------------------')
    7. print('Excel Data to CSV:\n', df.to_csv(index=False))