Python 如何分离DataFrame中的空格字符串

源数据样式:(Excel数据,列数据被存储为空格分割的字符串格式)

目标样式

过程实现:

  • import pandas as pd
  • df = pd.read_excel(pathname,sheet_name ='Sheet3')
  • list1 =[]
    df1 = df.iloc[:5,:1]    #仅对前五行数据处理了
    for i in range(len(df1)):
        list = df1.iloc[i][0].strip().split(' ')
        list1.append(list)
    print(list1)
  • df = pd.DataFrame(list1,columns=['Province','City','Country','Longitude','Latitude'])
    df

拓展实现:

  • df_point = df.iloc[:,3:5].copy()
    df_point

猜你喜欢

转载自blog.csdn.net/fuli0120/article/details/84591806