Search code examples
pythonpandasdataframedictionarypypdf

Python dictionary to pandas dataframe missing key values


I'm using Python 3.8 on windows 64.

I used PyPDF2 to find strings. I defined these values into dictionary using the code below:

keys=range(7)
values = (Docket, Date, CC, Owner, Scope, Crew, Additional)
dict_convert = dict(zip(keys,values))
print(dict_convert)

dict_convert print is below and shows range=7 (keys 0 to 6)

{0: '149623', 1: '21/10/19', 2: 'UTILITIES', 3: 'Camille .', 4: '008-lilyÞeld Rd-grove To Ryan-stop Slow-134-01, Rol_1268472_20190923-161408, ', 5: '5', 6: 'None'}

When I parse this into Pandas DataFrame only keys 0 to 4 are output. Any ideas why? Thanks in advance.

df = pd.DataFrame.from_dict(dict_convert, orient='index',dtype=None)
print(df.head())

                                                   0
0                                             149623
1                                           21/10/19
2                                          UTILITIES
3                                          Camille .
4  008-lilyÞeld Rd-grove To Ryan-stop Slow-134-01...

Solution

  • Because if use DataFrame.head it filter first 5 rows.

    If want see all data in small DataFrame:

    print(df)
    

    If there is more rows and added ... use:

    #temporaly display all rows
    with pd.option_context('display.max_rows', -1):
        print (df)