df.head(10)
XYZVal
0 {"X":"56.68","Y":"51.56","Z":"100"}
1 {"X":"58.05","Y":"52.37","Z":"62.6"}
2 {"X":"59.32","Y":"54.48","Z":"69.59"}
3 {"X":"58.51","Y":"36.36","Z":"82.76"}
4 {"X":"65.21","Y":"60.26","Z":"71.06"}
5 {"X":"57.64","Y":"52.07","Z":"67.89"}
6 {"X":"58.24","Y":"50","Z":"75"}
7 {"X":"57.69","Y":"52.13","Z":"68.64"}
8 {"X":"57.83","Y":"53.05","Z":"65.92"}
9 {"X":"60.87","Y":"51.73","Z":"71.35"}
如何通过选择X将上述数据框转换为新数据框:
{ 56.68 ,58.05 ,59.32 ,58.51 ,65.21 ,57.64 ,58.24 ,57.69 ,57.83 ,60.87 }
df.info() 表演
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 100 entries, 0 to 99
Data columns (total 1 columns):
XYZVal 100 non-null object
dtypes: object(1)
答案 0 :(得分:0)
我会做这样的事情:
df_list = df['XYZVal'].to_list()
new_df = pd.DataFrame(df_list)
X_df = new_df['X']
答案 1 :(得分:0)
如果TestActivity
已经包含字典,请使用:
XYZVal
如果列条目是字符串,则只需使用:
df.XYZVal.apply(lambda x: x["X"])
结果(两种方式)
import json
df['XYZVal'].apply(lambda x: json.loads(x)["X"])