0

How can I convert datatyp: Series to Pandas

Data example:

numpy_data = np.array([[1, 2], [3, 4], [1, 1]])
df = pd.DataFrame(data=numpy_data, index=[1,2,3], columns=["column1", "column2"])

Here I get the pandas.core.frame.Pandas data type for every row:

for row in df.itertuples():   
    print(row)
    print(type(row))

But if I read a single row I get pandas.core.series.Series

print(type(df.iloc[1]))

How can I convert series.Series to frame.Pandas?

Thomas
  • 1
  • 3
  • You could do this: https://stackoverflow.com/questions/59092561/how-to-use-iterator-in-while-loop-statement-in-python But why though? – Nick ODell Dec 28 '21 at 18:05
  • It would help if you included a small reproducible example. There's some good stuff at https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples about writing good reproducible examples for pandas. I think it would also help a bit if you gave more context around what you're actually trying to do. Looping over a pandas dataframe is rarely the best way to do things. – Eric Dec 28 '21 at 20:28

0 Answers0