Questions tagged [iteritems]

27 questions
15
votes
5 answers

Databricks: Issue while creating spark data frame from pandas

I have a pandas data frame which I want to convert into spark data frame. Usually, I use the below code to create spark data frame from pandas but all of sudden I started to get the below error, I am aware that pandas has removed iteritems() but my…
data en
  • 431
  • 1
  • 2
  • 9
9
votes
1 answer

AttributeError: 'dict' object has no attribute 'iteritems'

Question:I am getting an error while running the below code . I am new to this and not sure how to fix the issue. creae function to assign each coordinates point to its borough. def find_borough(lat,lon): """ return the borough…
Victor
  • 181
  • 2
  • 2
  • 4
5
votes
2 answers

Python dictionary not updating as expected in a loop

I am trying to create a dictionary which summarizes another. I would like the summary_dict to only be updated when the key matches the "parent" value in the details_dict. What I have written does not seem to be accessing the summary_dict as I would…
LoveMeow
  • 1,141
  • 2
  • 15
  • 26
4
votes
3 answers

Does python's dict.items() always return the same order?

Is it guaranteed that python 2.X's built-in methods dict.items() and dict.iteritems() will always return items in the same order? Or are these methods non-deterministic?
Saqib Ali
  • 11,931
  • 41
  • 133
  • 272
4
votes
2 answers

Iterating through YAML list in python

I'm trying to read a YAML file and print out the list I have on there in order of what it is in the file. So YAML: b: ... a: ... And my python is: for key, value in yaml.load(open(input_file)).items(): print(str(key)) The output…
Rikg09
  • 165
  • 2
  • 2
  • 14
3
votes
1 answer

Error while iterating over dataframe column's entries: "AttributeError: 'Series' object has no attribute 'iteritems'"

Using pandas version 2, I get an error when calling iteritems. for event_id, region in column.iteritems(): pass The following error message appears: Traceback (most recent call last): File…
jordimaggi
  • 99
  • 1
  • 11
2
votes
2 answers

AssertionError: Number of manager items must equal union of block items # manager items: 6004, # tot_items: 6005

My code: for column_name, column_data in summary_words.iteritems(): if column_name != "summary" and column_name != "text" and column_name != "score" and column_name != "helpfulness": summary_words[column_name] =…
Jack Cummins
  • 41
  • 1
  • 1
  • 8
1
vote
1 answer

Converting Poorly formed dictionary with pandas

I have a poorly formatted dictionary that uses numbers as keys in a nested dictionary, and not all keys in the top level have the same number of nested items. Example: {'Option 1': {'0': 'es_LA', '1': 'de_DE', '2': 'fr_FR'}, 'Option 2': {'0':…
corn
  • 11
  • 1
1
vote
2 answers

iteritems() in dataframe column

I have a dataset of U.S. Education Datasets: Unification Project. I want to find out Number of rows where enrolment in grade 9 to 12 (column: GRADES_9_12_G) is less than 5000 Number of rows where enrolment is grade 9 to 12 (column: GRADES_9_12_G)…
superduper
  • 401
  • 1
  • 5
  • 16
1
vote
1 answer

iteritems() DateFrame output mechanics and append() output into a new DataFrame

Ok, enough is enough. I need help with this iteritems() and append() procedeure... Here we have some Time Series Price Data for barrels of Beer, and Whiskey... Beer Whiskey Date 1978-12-29 22.60 86.50 1979-01-02 22.68 …
1
vote
2 answers

Group array by the first element value Python

i have an Array arr = [title, fileurl] so when i do print arr it goes like this: ['name1', 'url1'] ['name1', 'url2'] ['name1', 'url3'] ['name2', 'url1'] ['name2', 'url2'] ['name3', 'url1'] I would like to group these array by the first element, it…
1
vote
1 answer

enumerate with six library in python dictionary

I can use enumerate with python dictionary like so: for count, (key, value) in enumerate(my_dict.iteritems(), 1): print key, value, count How do I use enumerate with the iteritems function from the six library?
user308827
  • 21,227
  • 87
  • 254
  • 417
0
votes
2 answers

how to subtract previous row value from current row value based on condition in pandas DataFrame?

When performing a conditional substraction, where I subtract the previous row value from the current row value for the columns (Jan - AnnualMean) for those rows where the values from the ID column is not equal to 1 or 8. How to do that? I tried the…
Olli
  • 295
  • 4
  • 14
0
votes
1 answer

Pandas create csv file with team name based on value in data frame column using iterrows

Goal: Create a data frame per NFL team roster Basis Data frame: print(df_teams) Team Active since Regular season record ... Games Played Team_web Team_url 0 …
Daniel
  • 15
  • 3
0
votes
1 answer

Store iteritems-Result in dataframe

Goal: Add a column ('Team_url') to my nfl teams dataframe (df_teams) with each teams website-url. Problem: If I print the url, it works just fine. If I try to store it to df_teams['Team_url'], it only stores the last result of the…
Daniel
  • 15
  • 3
1
2