0
import pandas as pd

# Load the output dataframe
output_df = pd.read_excel('/content/drive/MyDrive/project/Data_Extraction_and_NLP TestAssignment/Output Data Structure.xlsx')

# URL_ID 44, 57, 144 do not exist, drop those rows
output_df.drop([44-37, 57-37, 144-37], axis=0, inplace=True)

# List of variables to assign to dataframe columns
variables = [
    positive_score,
    negative_score,
    polarity_score,
    subjectivity_score,
    avg_sentence_length,
    Percentage_of_Complex_words,
    Fog_Index,
    avg_sentence_length,
    complex_word_count,
    word_count,
    avg_syllable_word_count,
    pp_count,
    average_word_length
]

for i, var in enumerate(variables):
  output_df.iloc[:,i+2] = var

I was expecting a csv file with all these parameters as output but the output I am getting is and this is the error I get:

ValueError Traceback (most recent call last) in <cell line: 26>() 25 26 for i, var in enumerate(variables): ---> 27 output_df.iloc[:,i+2] = var

2 frames /usr/local/lib/python3.10/dist-packages/pandas/core/indexing.py in _setitem_with_indexer_split_path(self, indexer, value, name) 1848 return self._setitem_with_indexer((pi, info_axis[0]), value[0]) 1849 -> 1850 raise ValueError( 1851 "Must have equal len keys and value " 1852 "when setting with an iterable"

ValueError: Must have equal len keys and value when setting with an iterable

Himanshu Panwar
  • 216
  • 2
  • 7
sp8
  • 1
  • 1
  • Can you provide a sample of the contents of output_df after performing the drop operation, and provide an idea of what you expect the output to be after enumerating the variables? [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for best practices related to Pandas questions. – itprorh66 Jun 11 '23 at 13:00

0 Answers0