gpt4 book ai didi

python - 从 Dataframe 中删除行会导致在 Python 中分布 dataframe

转载 作者:行者123 更新时间:2023-12-01 09:00:15 25 4
gpt4 key购买 nike

我有以下数据框 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)

最佳答案

使用

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

关于python - 从 Dataframe 中删除行会导致在 Python 中分布 dataframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52509972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com