从Dataframe中删除行导致在Python中分发DataFrame

时间:2018-09-26 04:30:16

标签: python pandas dataframe

我在数据框nbr2下方:

    Postal_Code     Borough     Neighborhood
0   M1B     Scarborough     Rouge, Malvern
1   M4C     East York   Woodbine Heights
2   M4E     East Toronto    The Beaches
3   M4L     East Toronto    The Beaches West, India Bazaar
4   M4M     East Toronto    Studio District
5   M4N     Central Toronto     Lawrence Park

应用以下代码过滤掉行:

neighbor = nbr2.drop(nbr2[nbr2['Borough'].str.contains("Toronto")==False].index, axis=0, inplace=True)

数据帧的分布如下:

  Postal_Code           Borough  \
 37         M4E      East Toronto   
 41         M4K      East Toronto   
 42         M4L      East Toronto   
 43         M4M      East Toronto   
                                         Neighborhood  
37                                        The Beaches  
41                     The Danforth West\n, Riverdale  
42                   The Beaches West\n, India Bazaar  
43                                  Studio District\n  

下面的代码也导致类似的结构:

# define the dataframe columns
column_names = ['Postal_Code','Borough', 'Neighborhood'] 
# instantiate the dataframe
neighbor = pd.DataFrame(columns=column_names)

neighbor = nbr2.drop(nbr2[nbr2['Borough'].str.contains("Toronto")==False].index, axis=0, inplace=True)

1 个答案:

答案 0 :(得分:1)

使用

pd.set_option('display.expand_frame_repr', False)