它的新手在这里再次.我想问你一次,如何显示原始输出,然后再显示修改或编辑输出.这是我的代码
import pandas as pd
source = r'C:\Users\pulun\hbrag08\Durga Software\Complete Python Package\Python for Data Science\04. Pandas\DataFrame\employee_data.csv'
df = pd.read_csv(source,
usecols=['eno','ename','esal','city','country'],
index_col='eno',
sep=';')
df.rename(columns={'country': 'country name'},inplace=True)
print(df.sort_values(['esal']).loc[df['country name'].isin(
['Indonesia', 'USSR'])].head(n=6))
df.loc[(df['esal'] <= 1300000) & (df['country name'].isin(
['Indonesia', 'USSR']))] = df.loc[(df['esal'] <= 1300000) & (df['country name'].isin(
['Indonesia', 'USSR']))].apply(lambda x: x*2)
print('your solution here')
字符串
原始输出如下
ename esal city country name
eno
2840 Duffy Stood 1039768.45 9488 Milwaukee Plaza USSR
5590 Sawyere Clogg 1096587.82 3409 Rockefeller Alley USSR
730 Garret Attew 1104028.84 7 Walton Point USSR
9040 Marve Coalburn 1207724.68 97 Susan Point USSR
1620 Chrotoem Cleeve 1280881.36 NaN USSR
9500 Eleanore Cabrera 1294722.19 2401 Hovde Way Indonesia
型
我想要的是类似的输出以上,但与esal是一倍。
after输出必须看起来像下面这样:
ename esal city country name
eno
2840 Duffy Stood 2079536.90 9488 Milwaukee Plaza USSR
5590 Sawyere Clogg 2193175.64 3409 Rockefeller Alley USSR
730 Garret Attew 2208057.68 7 Walton Point USSR
9040 Marve Coalburn 1207724.68 97 Susan Point USSR
1620 Chrotoem Cleeve 2415449.36 NaN USSR
9500 Eleanore Cabrera 2589444.38 2401 Hovde Way Indonesia
型
对于你的帮助,我表示非常感谢
3条答案
按热度按时间7gyucuyw1#
试试看:
字符串
k75qkfdt2#
尝试替换:
字符串
这几行代码:
型
guicsvcw3#
只需创建一个名为
esal_orig
的新列,您就可以比较前后。个字符