简体   繁体   中英

how to query the memory layout of pandas.dataframe

I want to to query the memory layout of a pandas.dataframe. More explicitly, given a dataframe df (say, of the type np.float32), I would like to known if it is column-contiguous or row-contiguous.

you can examine the flags attribute of the underlying numpy array. The underlying numpy array can be accessed through the pd.DataFrame.values

example:

import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.random(12).reshape(4,3), columns=list('abc'))
df.values.flags
#outputs:
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : False
WRITEABLE : True
ALIGNED : True
WRITEBACKIFCOPY : False
UPDATEIFCOPY : False

As you can see from the output, in this case the data is row-contiguous ( C_CONTINUOUS ). F_CONTINUOUS signifies that the data is column-contiguous

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