sütunda value
değerler tip list
, kullanım varsa:
df['value'] = df['value'].str[0]
Veya:
df['value'] = df['value'].str.get(0)
Docs.
Örnek:
df = pd.DataFrame({'value':[[63],[65],[64]]})
print (df)
value
0 [63]
1 [65]
2 [64]
#check type if index 0 exist
print (type(df.loc[0, 'value']))
<class 'list'>
#check type generally, index can be `DatetimeIndex`, `FloatIndex`...
print (type(df.loc[df.index[0], 'value']))
<class 'list'>
df['value'] = df['value'].str.get(0)
print (df)
value
0 63
1 65
2 64
kullanım str.strip
strings
ise daha sonra astype
tarafından sayısal dönüştürmek:
df['value'] = df['value'].str.strip('[]').astype(int)
Örnek: O sütunun içeriği ne
df = pd.DataFrame({'value':['[63]','[65]','[64]']})
print (df)
value
0 [63]
1 [65]
2 [64]
#check type if index 0 exist
print (type(df.loc[0, 'value']))
<class 'str'>
#check type generally, index can be `DatetimeIndex`, `FloatIndex`...
print (type(df.loc[df.index[0], 'value']))
<class 'str'>
df['value'] = df['value'].str.strip('[]').astype(int)
print (df)
value
0 63
1 65
2 64
, bu bir dizi '' [63] '' veya bir liste [63] '? – EdChum