0

example code:

import numpy as np
import pandas as pd

df = pd.DataFrame()
arr = np.array(range(5))
vec = arr.reshape(-1,1)

# df['c0'] = vec # this line could not work
df['arr'] = arr # but we allow this one, just giving a default index
df['c1'] = vec # df has a index now, and this line works
df.index = range(0,10,2) # index changed
df['c2'] = vec # df changed index. but c1 and c2 are just the same.

print(df)

'c1' and 'c2' are the same, meaning that the assign do not care what the index really is at all, just length checking.

what is the point of making 'c0' invalid? would it be better if we just set a default index like range(5) and allow that kind of assignment?

add version info:

import sys
print(sys.version_info)
print('numpy: ' + np.__version__)
print('pandas: ' + pd.__version__)

sys.version_info(major=3, minor=9, micro=2, releaselevel='final', serial=0)

numpy: 1.20.1

pandas: 1.2.3

0 Answers0