How do I empty a python pandas dataframe? -


very new pandas please let me know how empty data-frame of data please?

either use .loc set values none

df.loc[:] = none 

or if want more explicit

empty_df = pd.dataframe(data=none, columns=full_df.columns, index=full_df.index) 

speed wise .loc lot faster, unless doing many many times, or dataframe large, not see difference.

n = 500000  values = np.random.uniform(size=(n, 5))  def using_loc():     df = pd.dataframe(values, columns=list('abcde'))     df.loc[:] = none %timeit using_loc() # 100 loops, best of 3: 3.49 ms per loop  def new_df():     df = pd.dataframe(values, columns=list('abcde'))     pd.dataframe(data=none, index=df.index, columns=df.columns) %timeit new_df() # 10 loops, best of 3: 45.4 ms per loop 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -