Здравствуйте, у меня проблема c проблема, я работаю с большим CSV (в среднем 600x1000, файлы, которые создаются программным обеспечением, к которому у меня нет доступа, и, к сожалению, некоторые из них имеют неправильный формат:
dirt issue is when i use load the file with this code :
df=read_csv(csv_path,sep=';')
both cells circled in red are considered as column names so what i've done now is :
df=read_csv(csv_path,sep=';',names=None)
it worked exactly as i expected to ! But now here is my real problem i need to transpose this data frame and add real column names so here is my code :
df=read_csv(csv_path,sep=';',names=None)
col_names =["src_label"]
for i in range(len(df.columns)-1):
col_names.append("Result_"+str(i))
df=df.transpose()
data=df.to_dict
df1 = DataFrame(data, columns=col_names)
However i get the following error :
ValueError: DataFrame constructor not properly called!
i've tried to call with
df1 = DataFrame(df, columns=col_names)
i also tried
df.columns=col_names
after having transposed it obviously but i has no effects
and i also tried
df.names=col_names
i got a warning saying 'can't set new values by creating an attribute'
and last try was :
for j in range(len(col_names)-1):
df = df.rename_axis(col_names[i], axis=i)
no errors but no effects either
EDIT :
just tried to read csv like this :
df=read_csv(csv_path,sep=';',header=None)
and got
ParserError: Error tokenizing data. C error: Expected 2 fields in line 2, saw 975
To help me, i need a solution to create a fresh dataframe from the previous one and then adding the column names or dirctly add column names in the first datarame in order to get the following result :
введите описание изображения здесь