Is there a way to load into a specific column in excel/csv without dataframe(Pandas)
Question:
I am trying to load a list of items into a specific column of the csv.
I tried to look for a lot of answer and tutorial online and they only showed how to do it with dataframe.
I am wondering is there a way where I can just look for the Column name and load into that column since some of the excel sheet they have different column names?
data = pd.read_excel(filenames)
data.loc['Price']=pricelist
data.to_csv(filenames,index=False, encoding='utf-8')
This is my current code, it doesnt work and return an error of "cannot set a row with mismatched columns"
Items
Stock
Price(Search by this column name)
Item1
5
trying to load into this column
Item 2
76
trying to load into this column
Answers:
DataFrame.loc
is used to access rows and columns.
Your line data.loc['Price']=pricelist
attempts to set the row with the name "Price", not the column.
Have you instead tried data['Price']=pricelist
?
I am trying to load a list of items into a specific column of the csv.
I tried to look for a lot of answer and tutorial online and they only showed how to do it with dataframe.
I am wondering is there a way where I can just look for the Column name and load into that column since some of the excel sheet they have different column names?
data = pd.read_excel(filenames)
data.loc['Price']=pricelist
data.to_csv(filenames,index=False, encoding='utf-8')
This is my current code, it doesnt work and return an error of "cannot set a row with mismatched columns"
Items | Stock | Price(Search by this column name) |
---|---|---|
Item1 | 5 | trying to load into this column |
Item 2 | 76 | trying to load into this column |
DataFrame.loc
is used to access rows and columns.
Your line data.loc['Price']=pricelist
attempts to set the row with the name "Price", not the column.
Have you instead tried data['Price']=pricelist
?