我想在csv中设置“status”列的格式,并将字符串保留在逗号('sometext',)旁边的单引号中
例如:
如第2行及;3-如果在任何列值中发现多个值,则应使用管道符号(|)连接,例如电话充电器
预期的输出应粘贴在相同的状态列中,如下所示
我的尝试(无效):
import pandas as pd
df = pd.read_csv("test projects.csv")
scol = df.columns.get_loc("Status")
statusRegex = re.
compile("'\t',"?"'\t',") mo = statusRegex.search (scol.column)
假设您有df as:
df:
df:
谢谢大家的帮助和建议。请查找最终工作代码
df=pd.read\u csv('test projects.csv'))
行=len(df['input'])
def get_值(值):
阿尔斯特=[]
ans_lst=[]
对于范围内的r(行):
df['a']=allst
df['b']=ans_lst
df.to_csv(“Output.csv”,index=False)
其他帮助:您不需要使用read_excel,因为csv不是excel格式。它是标准格式的逗号分隔值。在这种情况下,您可以这样做:
相关问题 更多 >
编程相关推荐