Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23218

Python, pandas Dataframe row

$
0
0

I am trying to iterate through each row of a Dataframe. However, using row on Column B (a comma separated field) is splitting this into single characters.

Column AColumn B
pet.dog,cat

The code I’m using:

for index, row in df.iterrows():    A1 = row['Column A']    A2 = row['Column B']    print(A2)    A3 = add_units['Column A'].str.split(',').tolist()    A4 = list(A3)    A5 = json.dumps(A4)    print(A5)

I have tried list and json dumps and the format looks correct after the print.But then I can’t iterate and get the error list index out of range.


Viewing all articles
Browse latest Browse all 23218

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>