从另一个数据帧传输时,DataFrame为空白

时间:2018-05-15 07:04:31

标签: python-3.x pandas dataframe

我正在使用现有数据框中的某些列创建新数据框。

 eventdata1 = pd.DataFrame({
    "competition":eventdata['competition'],
    "hometeam":eventdata['hometeam_team1'],
    "awayteam":eventdata['awayteam_team2'],
    "team":eventdata['Team Against'],
    "MatchDateTime":eventdata['matchdatetime'],
    "EventDateTime":eventdata['eventdatetime'],
    "PreviousEventDateTime":eventdata['PreviousEventTime'],
    "Goal_Flag":eventdata['Goal_Flag']},
    columns =[['competition',
    'hometeam',
    'awayteam',
    'team',
    'MatchDateTime',
    'EventDateTime',
    'PreviousEventDateTime',
    'Goal_Flag']])

事实证明除了索引列之外,所有列都是空白的。 eventdata是现有的数据框架,eventadata1是我现在创建的数据框架。 建议非常感谢。 谢谢 ZEP。

3 个答案:

答案 0 :(得分:2)

使用rename,然后按子集过滤:

columns =['competition',
    'hometeam',
    'awayteam',
    'team',
    'MatchDateTime',
    'EventDateTime',
    'PreviousEventDateTime',
    'Goal_Flag']

d = {'hometeam_team1': 'hometeam', 
     'awayteam_team2':'awayteam', 
     'Against':'team',
     'matchdatetime':'MatchDateTime',
     'eventdatetime':'EventDateTime',
     'PreviousEventTime':'PreviousEventDateTime'}
eventdata1 = eventdata.rename(columns=d)[columns]

答案 1 :(得分:1)

试试这个;

eventdata1=pd.DataFrame()
my_columns =['competition',
    'hometeam',
    'awayteam',
    'team',
    'MatchDateTime',
    'EventDateTime',
    'PreviousEventDateTime',
    'Goal_Flag']
for col in my_columns:
    eventdata1[col]=eventdata[col]

有更优雅的解决方案,但上述肯定有效。 你也可以试试;

eventdata1=pd.DataFrame(eventdata[my_columns])

最佳!

答案 2 :(得分:1)

你可以这样做,

 Make GoogleMap  object global to change the view programatically on MenuItem selection



 @Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    if (id == R.id.normal) {
        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    } else if (id == R.id.hybrid) {

    map.setMapType(GoogleMap.MAP_TYPE_HYBRID);

    } else if (id == R.id.satellite) {

    map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);


    } else if (id == R.id.Terrain) {
        map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);

    }
    return super.onOptionsItemSelected(item);
}