Skip to content
Advertisement

Long dictionary(tuple values inside+ different lengths) variable to XLXS file Not working

I am trying to make a XLXS file with the hot3 dictionary value. I’ve tried with the pd.DataFrame.from_dict But it didn’t work properly. To make a XLXS file with value is pretty hard for me, even I read the Pandas docs… Could I get some help please?

I’ve tried to search some answers but could not find it!

import openpyxl
import pandas as pd

wb = openpyxl.Workbook()
sheet = wb.active

sl = sorted_list[0]

hot3 = {('BitcoinBTC',): ('Oct 25, 2021', 'Oct 24, 2021', 'Oct 20, 2021', 'Oct 20, 2021'), ('EthereumETH',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25,2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021'), ('CardanoADA',): ('깃허브가 아닌 다른 저장소 사이트 [확인해 봐야함]',), ('SolanaSOL',): ('Oct 25, 2021', 'Oct 25, 2021',
 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021'), ('XRPXRP',): ('Oct 23, 2021', 'Oct 21, 2021', 'Oct 21, 2021', 'Oct 18, 2021', 'Oct 18, 2021', 'Oct 18, 2021', 'Oct 7, 2021', 'Sep 21, 2021', 'Sep 16, 2021', 'Sep 5, 2021'), ('PolkadotDOT',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021',
'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021'), ('DogecoinDOGE',): ('Aug 20, 2021', 'Aug 21, 2021'), ('USD', 'CoinUSDC'): ('Jun 3, 2021', 'Aug 3, 2018'), ('TerraLUNA',): ('1'), ('ChainlinkLINK',): ('Oct 25, 2021', 'Oct 19, 2021'), ('AvalancheAVAX',): ('Oct 22, 2021', 'Oct 22, 2021', 'Oct 21, 2021', 'Oct 21, 2021', 'Oct 21, 2021', 'Oct 20, 2021', 'Oct 20, 2021', 'Oct 20, 2021', 'Oct 19, 2021', 'Oct 19, 2021'), ('Wrapped', 'BitcoinWBTC'): ('May 18, 2021',), ('LitecoinLTC',): ('Jun 10, 2021', 'Jun 11, 2020'), ('Binance', 'USDBUSD'): ('Feb 2, 2021',), ('AlgorandALGO',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 24, 2021', 'Oct 24, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 21, 2021', 'Oct 21, 2021'), ('Bitcoin', 'CashBCH'): ('??? [???]',), ('PolygonMATIC',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 24, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 21, 2021', 'Oct 21, 2021', 'Oct 21, 2021'), ('StellarXLM',): ('Oct 23, 2021', 'Oct 22, 2021', 'Oct 23, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021'), ('CosmosATOM',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021',
'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 24, 2021', 'Oct 24, 2021', 'Oct 22, 2021'), ('Internet', 'ComputerICP'): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 23, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 21, 2021'), ('FantomFTM',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 24, 2021', 'Oct 23, 2021', 'Oct 19, 2021'), ('Ethereum', 'ClassicETC'): ('Oct 19, 2021', 'Oct 11, 2021', 'Sep 29, 2021', 'Aug 10, 2021', 'May 4, 2021', 'Mar 25, 2020', 'Mar 21, 2020', 'Mar8, 2020', 'Jan 29, 2020', 'Jan 23, 2020'), ('TRONTRX',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 20, 2021', 'Oct 20, 2021', 'Oct 19, 2021', 'Oct 18, 2021', 'Oct 15, 2021', 'Oct 14, 2021', 'Oct 14, 2021', 'Oct 12, 2021'), ('THETATHETA',): ('Oct 23, 2021', 'Oct 22, 2021', 'Oct 20, 2021', 'Oct 20, 2021', 'Oct 11, 2021', 'Oct 4, 2021', 'Sep 8, 2021', 'Aug 13, 2021', 'Aug 9, 2021', 'Aug 9, 2021'), ('Bitcoin', 'BEP2BTCB'):
 ('Oct 25, 2021', 'Oct 24, 2021', 'Oct 20, 2021', 'Oct 20, 2021'), ('HederaHBAR',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 23, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021'), ('ElrondEGLD',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021'), ('TezosXTZ',): ('??? [???]',), ('NEAR', 'ProtocolNEAR'): ('Oct 22, 2021', 'Sep 6, 2021'), ('MoneroXMR',): ('Oct 18, 2021', 'Sep 1, 2021'), ('The', 'GraphGRT'): ('Oct 25, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 21, 2021', 'Oct 20, 2021', 'Oct 20, 2021', 'Oct 18, 2021', 'Oct 16, 2021', 'Oct 12, 2021'), ('PancakeSwapCAKE',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 19, 2021', 'Oct 16, 2021', 'Oct 12, 2021', 'Oct 11, 2021', 'Oct 8, 2021', 'Oct 7, 2021'), ('EOSEOS',): ('Oct 25, 2021', 'Oct 23, 2021', 'Oct 22, 2021', 'Oct 21, 2021',
 'Oct 21, 2021', 'Oct 20, 2021', 'Oct 20, 2021', 'Oct 18, 2021', 'Oct 15, 2021', 'Oct 13, 2021'), ('FlowFLOW',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021',
 'Oct 25, 2021', 'Oct 23, 2021', 'Oct 23, 2021', 'Oct 22, 2021'), ('AaveAAVE',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 24, 2021', 'Oct 22, 2021', 'Oct 18, 2021', 'Oct 18, 2021', 'Oct 14, 2021',
 'Oct 14, 2021', 'Oct 14, 2021'), ('KlaytnKLAY',): ('Oct 21, 2021', 'Oct 19, 2021'), ('IOTAMIOTA',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021'), ('eCashXEC',): ('Oct 25, 2021', 'Oct 22, 2021', 'Oct 19, 2021', 'Oct 19, 2021', 'Oct 29, 2020'), ('QuantQNT',): ('q'), ('KusamaKSM',): ('Jun 16, 2021', 'Jul 28, 2020', 'May 20, 2020', 'Nov 8, 2019'), ('HarmonyONE',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 24, 2021', 'Oct 24, 2021', 'Oct 24, 2021', 'Oct 24, 2021', 'Oct 23, 2021', 'Oct 23, 2021', 'Oct22, 2021'), ('Bitcoin', 'SVBSV'): ('Oct 21, 2021', 'Oct 21, 2021'), ('NeoNEO',): ('Oct 25, 2021', 'Oct 23, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 20, 2021', 'Oct 20, 2021', 'Oct 20, 2021', 'Oct 18, 2021',
 'Oct 8, 2021', 'Sep 22, 2021'), ('WavesWAVES',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 24, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 21, 2021', 'Oct 21, 2021'
), ('THORChainRUNE',): ('Oct 25, 2021', 'Oct 21, 2021', 'Oct 18, 2021', 'Oct 14, 2021', 'Oct 14, 2021', 'Oct 12, 2021', 'Oct 12, 2021', 'Oct 12, 2021', 'Oct 5, 2021', 'Sep 21, 2021'), ('StacksSTX',): ('Oct 25,2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 23, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 21, 2021', 'Oct 20, 2021'), ('TerraUSDUST',): ('z'), ('BitTorrentBTT',): ('Oct 1, 2021'
, 'Aug 27, 2021', 'Feb 1, 2021', 'Sep 28, 2020', 'Sep 17, 2020', 'Jun 25, 2020', 'Jun 3, 2020', 'Jun 1, 2020', 'Feb 18, 2020', 'Mar 6, 2019'), ('CeloCELO',): ('Oct 25, 2021', 'Sep 29, 2021'), ('ZcashZEC',): ('Oct 16, 2021', 'Oct 10, 2021'), ('HeliumHNT',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 24, 2021', 'Oct 24, 2021', 'Oct 24, 2021', 'Oct 24, 2021', 'Oct 23, 2021', 'Oct 23, 2021', 'Oct 23, 2021', 'Oct 23, 2021'),
 ('DashDASH',): ('Jun 5, 2021', 'Jun 7, 2021'), ('OMG', 'NetworkOMG'): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 22, 2021', 'Oct 21, 2021', 'Oct 6, 2021', 'Oct 6, 2021', 'Oct 6, 2021', 'Sep 24, 2021', 'Sep 22, 2021', 'Sep 13, 2021'), ('AmpAMP',): ('Sep 17, 2021', 'Dec 22, 2020', 'Dec 4, 2020'), ('CompoundCOMP',): ('Oct 22, 2021', 'Jun 27, 2020'), ('ArweaveAR',): ('Oct 11, 2021', 'Sep 5, 2021'), ('Curve', 'DAO', 'TokenCRV'): ('Feb 22, 2021',), ('DecredDCR',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 23, 2021'), ('HoloHOT',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 24, 2021', 'Oct 24, 2021', 'Oct 23, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021'), ('Theta', 'FuelTFUEL'): ('Oct 23, 2021'
, 'Oct 22, 2021', 'Oct 20, 2021', 'Oct 20, 2021', 'Oct 11, 2021', 'Oct 4, 2021', 'Sep 8, 2021', 'Aug 13, 2021', 'Aug 9, 2021', 'Aug 9, 2021'), ('NEMXEM',): ('a'), ('Enjin', 'CoinENJ'): ('Nov 2, 2017',), ('NexoNEXO',): ('Apr 20, 2018',), ('RevainREV',): ('Sep 23, 2020', 'Aug 18, 2020', 'Jun 5, 2020', 'Mar 26, 2020', 'Dec 20, 2019', 'Dec 17, 2019', 'Feb 2, 2018'), ('DecentralandMANA',): ('Oct 25, 2021', 'Oct 25, 2021',
'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 23, 2021', 'Oct 23, 2021', 'Oct 23, 2021', 'Oct 23, 2021'), ('ICONICX',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 16, 2021', 'Oct 14, 2021', 'Oct 14, 2021', 'Oct 12, 2021', 'Oct 8, 2021', 'Oct 8, 2021'), ('SushiSwapSUSHI',): ('Oct 11, 2021',), ('MinaMINA',): ('Oct 18, 2021', 'Sep 23, 2021'), ('QtumQTUM',): ('Jun 17, 2021', 'May 17, 2021'), ('ZilliqaZIL',): ('Oct 25, 2021', 'Sep 6, 2021'), ('TrueUSDTUSD',): ('Oct 25, 2021', 'Oct 21, 2021', 'Oct 12, 2021', 'Oct 6, 2021', 'Oct 5, 2021', 'Sep 30, 2021', 'Sep 15, 2021', 'Sep 2,2021', 'Aug 10, 2021', 'May 20, 2021'), ('yearn.financeYFI',): ('a'), ('XDC', 'NetworkXDC'): ('Apr 1, 2021', 'Aug 17, 2020'), ('CelsiusCEL',): ('Oct 11, 2021', 'Sep 27, 2021', 'Aug 29, 2019', 'Apr 16, 2018', 'Feb 5, 2018'), ('RavencoinRVN',): ('May 21, 2021', 'Dec 7, 2020'), ('Bitcoin', 'GoldBTG'): ('Apr 11, 2021', 'Aug 1, 2020'), ('TelcoinTEL',): ('Oct 7, 2021', 'Oct 4, 2021', 'Sep 24, 2021', 'Sep 22, 2021', 'Aug 23, 2021', 'Aug 20, 2021', 'Aug 13, 2021', 'Jul 26, 2021', 'Jul 22, 2021', 'Jun 17, 2021'), ('RenREN',): ('Oct 25, 2021', 'Oct 24, 2021', 'Oct 24, 2021', 'Oct 23, 2021', 'Oct 22, 2021', 'Oct 21, 2021', 'Oct 21,2021', 'Oct 21, 2021', 'Oct 19, 2021', 'Oct 18, 2021'), ('renBTCRENBTC',): ('Oct 25, 2021', 'Oct 24, 2021', 'Oct 24, 2021', 'Oct 23, 2021', 'Oct 22, 2021', 'Oct 21, 2021', 'Oct 21, 2021', 'Oct 21, 2021', 'Oct19, 2021', 'Oct 18, 2021'), ('HorizenZEN',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 24, 2021', 'Oct 22, 2021', 'Oct 20, 2021', 'Oct 18, 2021', 'Oct 16, 2021', 'Oct 15, 2021'), ('SerumSRM',): ('Oct 25, 2021', 'Oct 25, 2021', 'Oct 25, 2021', 'Oct 23, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 22, 2021', 'Oct 18, 2021', 'Oct 14, 2021', 'Oct 15, 2021')}


df_st = pd.DataFrame.from_dict(data=hot3)
df_st = df_st.transpose()
df_st.to_excel('hot2.xlsx')

Error message

  File ".test.py", line 83, in <module>
    df_st = pd.DataFrame.from_dict(data=hot3)
  File "C:UsersSKDesktopfastvenvlibsite-packagespandascoreframe.py", line 1593, in from_dict
    return cls(data, index=index, columns=columns, dtype=dtype)
  File "C:UsersSKDesktopfastvenvlibsite-packagespandascoreframe.py", line 614, in __init__
    mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
  File "C:UsersSKDesktopfastvenvlibsite-packagespandascoreinternalsconstruction.py", line 464, in dict_to_mgr
    return arrays_to_mgr(
  File "C:UsersSKDesktopfastvenvlibsite-packagespandascoreinternalsconstruction.py", line 119, in arrays_to_mgr
    index = _extract_index(arrays)
  File "C:UsersSKDesktopfastvenvlibsite-packagespandascoreinternalsconstruction.py", line 635, in _extract_index
    raise ValueError("All arrays must be of the same length")
ValueError: All arrays must be of the same length

Advertisement

Answer

Use pd.DataFrame.from_dict:

df_st = pd.DataFrame.from_dict(hot3, orient='index')
print(df_st)

# Output:
                                            0             1             2             3             4             5             6             7             8             9
(BitcoinBTC,)                    Oct 25, 2021  Oct 24, 2021  Oct 20, 2021  Oct 20, 2021          None          None          None          None          None          None
(EthereumETH,)                   Oct 25, 2021  Oct 25, 2021  Oct 25, 2021  Oct 25, 2021   Oct 25,2021  Oct 25, 2021  Oct 25, 2021  Oct 25, 2021  Oct 25, 2021  Oct 25, 2021
(CardanoADA,)    깃허브가 아닌 다른 저장소 사이트 [확인해 봐야함]          None          None          None          None          None          None          None          None          None
(SolanaSOL,)                     Oct 25, 2021  Oct 25, 2021  Oct 25, 2021  Oct 25, 2021  Oct 25, 2021  Oct 25, 2021  Oct 25, 2021  Oct 25, 2021  Oct 25, 2021  Oct 25, 2021
(XRPXRP,)                        Oct 23, 2021  Oct 21, 2021  Oct 21, 2021  Oct 18, 2021  Oct 18, 2021  Oct 18, 2021   Oct 7, 2021  Sep 21, 2021  Sep 16, 2021   Sep 5, 2021
...                                       ...           ...           ...           ...           ...           ...           ...           ...           ...           ...
(TelcoinTEL,)                     Oct 7, 2021   Oct 4, 2021  Sep 24, 2021  Sep 22, 2021  Aug 23, 2021  Aug 20, 2021  Aug 13, 2021  Jul 26, 2021  Jul 22, 2021  Jun 17, 2021
(RenREN,)                        Oct 25, 2021  Oct 24, 2021  Oct 24, 2021  Oct 23, 2021  Oct 22, 2021  Oct 21, 2021   Oct 21,2021  Oct 21, 2021  Oct 19, 2021  Oct 18, 2021
(renBTCRENBTC,)                  Oct 25, 2021  Oct 24, 2021  Oct 24, 2021  Oct 23, 2021  Oct 22, 2021  Oct 21, 2021  Oct 21, 2021  Oct 21, 2021   Oct19, 2021  Oct 18, 2021
(HorizenZEN,)                    Oct 25, 2021  Oct 25, 2021  Oct 25, 2021  Oct 25, 2021  Oct 24, 2021  Oct 22, 2021  Oct 20, 2021  Oct 18, 2021  Oct 16, 2021  Oct 15, 2021
(SerumSRM,)                      Oct 25, 2021  Oct 25, 2021  Oct 25, 2021  Oct 23, 2021  Oct 22, 2021  Oct 22, 2021  Oct 22, 2021  Oct 18, 2021  Oct 14, 2021  Oct 15, 2021

[81 rows x 10 columns]
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement