简体   繁体   English

我想从第一列打印 2 到 5 之间的值

[英]I want to print the value between 2 to 5 from 1first columns

I want to print the value between 2 to 5 from 1first columns.我想从第一列打印 2 到 5 之间的值。

df5 = pd.DataFrame({
    'colA': ['C4GSP3JOIHJ2', 'CAGPS3JOIHJ2','CALCG3EST2','CLCCV3JOIHJ2','CLCNF3JOIHJ2','CLCQU3JOIHJ2','CLSMS3JOIHJ2','CMICO3JOIHJ2'],
    })

output look like this output 看起来像这样

在此处输入图像描述

df['output'] = df.colA.apply(lambda x: x[1:6]) 

should work.应该管用。 Docs for apply function: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.apply.html申请 function 的文档: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.apply.html

df5['output']=df5['colA'].str[1:6]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想一次添加一个值,但是要添加两次,如果我先打印该值,它只会被添加一次 - I want to add a value once but gets added twice and if i print the value first it only gets add once 我想在 python 中打印名字姓氏和姓氏名字 - I want to print first name last and second name first in python 如何从字典中获取输入? 并打印所需的值..我想使用输入 function 并打印“zinger burer” - how to take input from dictionaries ? and print that desired value ..i want to use input function and print “zinger burer” 我想计算数据框中两列之间有多少不同的值用于混淆矩阵 - I want to count how many different value between two columns in dataframe for confusion matrix 我想在 python 中打印一个从 1 到 10 的嵌套循环,如图所示 10 行和 10 列 - I want to print in python a nested loop from 1 to 10 as shown 10 rows and 10 columns 我想打印一个我从 def 值得到的数字。 但我想将 def 转换为 integer。有没有办法 - I want to print a number i got from a def value. but i want to convert the def into an integer. Is there a way 大家好,我是 python 的新手。 我想使用 key() 方法打印字典中第一个键的值 - Hello everyone, I am new to python. I want to print the value of the first key in dictionary using key() method 我希望能够从python中找到excel中的值并在下一列中打印该值 - I want to be able to locate a value in excel from python and print the value in the next column 我只想打印来自 GoogleNews 的 1 个故事 - I only want to print 1 story from GoogleNews 如何从列表中查找并打印出特定值(至少我认为那是我想做的事?) - How to find and print out of a specific value from a list (at least i think thats what i want to do?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM