我有一个csv文件,其中Date
列的2002-08-31
列具有以下格式YEAR-MONTH-DAY
,YEAR
。
我想将这些列拆分为3个不同的列,使得该表的MONTH
列DAY
列<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ecebuc.gesmediaplayer">
<permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MediaPlaybackService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
<receiver android:name="android.support.v4.media.session.MediaButtonReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
</intent-filter>
</receiver>
</application>
和 public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private final int REQUEST_CODE_GESPLAYER_EXTERNAL_STORAGE = 101;
private static final int STATE_PAUSED = 0;
private static final int STATE_PLAYING = 1;
private static int currentState;
private MediaBrowserCompat gesMediaBrowser;
private MediaControllerCompat gesMediaController;
public MediaControllerCompat.TransportControls gesPlaybackController;
private Button playPauseToggleButton;
private MediaBrowserCompat.ConnectionCallback mediaBrowserCallbacks = new MediaBrowserCompat.ConnectionCallback() {
@Override
public void onConnected() {
super.onConnected();
try {
//create the media controller and register the callbacks to stay in sync
gesMediaController = new MediaControllerCompat(MainActivity.this, gesMediaBrowser.getSessionToken());
gesMediaController.registerCallback(mediaControllerCallbacks);
//save the controller and define the easy access transport controls in the object
MediaControllerCompat.setMediaController(MainActivity.this, gesMediaController);
gesPlaybackController = gesMediaController.getTransportControls();
//Display initial state
MediaMetadataCompat metadata = gesMediaController.getMetadata();
PlaybackStateCompat pbState = gesMediaController.getPlaybackState();
} catch( RemoteException e ) {
}
}
@Override
public void onConnectionSuspended() {
// The Service has crashed. Disable transport controls until it automatically reconnects
}
@Override
public void onConnectionFailed() {
// The Service has refused our connection
Log.d("onConnectionFail: ", "the service hasn't been able to connect");
}
};
private MediaControllerCompat.Callback mediaControllerCallbacks = new MediaControllerCompat.Callback() {
@Override
public void onMetadataChanged(MediaMetadataCompat metadata) {
super.onMetadataChanged(metadata);
}
@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
super.onPlaybackStateChanged(state);
if( state == null ) {
Log.d("onPlaybackChange: ", "the state is null");
Toast.makeText(MainActivity.this,
"onPlaybackStateChange: the state is null",
Toast.LENGTH_SHORT)
.show();
return;
}
switch( state.getState() ) {
case PlaybackStateCompat.STATE_PLAYING: {
currentState = STATE_PLAYING;
break;
}
case PlaybackStateCompat.STATE_PAUSED: {
currentState = STATE_PAUSED;
break;
}
}
}
@Override
public void onSessionDestroyed(){
// Override to handle the session being destroyed
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//grab the buttons for media playback control
playPauseToggleButton = (Button)findViewById(R.id.playPause_btn);
//request permissions for external storage
if (ContextCompat.checkSelfPermission(this,
android.Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Permission have not been granted
ActivityCompat.requestPermissions(this,
new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE},
REQUEST_CODE_GESPLAYER_EXTERNAL_STORAGE);
}
else{
//permissions have already been granted
}
//initiate connection to the MediaPlaybackService through MediaBrowser
gesMediaBrowser = new MediaBrowserCompat(this,
new ComponentName(this, MediaPlaybackService.class),
mediaBrowserCallbacks, getIntent().getExtras());
gesMediaBrowser.connect();
//Attach listeners to them
playPauseToggleButton.setOnClickListener(this);
// space here for other buttons
// sapce here for other buttons
}
@Override
protected void onStart() {
super.onStart();
//gesMediaBrowser.connect();
}
/*protected void onStop() {
super.onStop();
// (see "stay in sync with the MediaSession")
if( gesMediaController.getPlaybackState().getState() == PlaybackStateCompat.STATE_PLAYING ) {
gesPlaybackController.pause();
}
gesMediaBrowser.disconnect();
}*/
@Override
protected void onDestroy() {
super.onDestroy();
/*if (gesMediaController != null) {
gesMediaController.unregisterCallback(mediaControllerCallbacks);
gesMediaController = null;
}
if(gesMediaBrowser != null && gesMediaBrowser.isConnected()) {
gesMediaBrowser.disconnect();
gesMediaBrowser = null;
}*/
if( gesMediaController.getPlaybackState().getState() == PlaybackStateCompat.STATE_PLAYING ) {
gesPlaybackController.pause();
}
gesMediaBrowser.disconnect();
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.playPause_btn:
//has to be dealt with accordingly, based on the current state of mediaplayer
int currentState = gesMediaController.getPlaybackState().getState();
if(currentState == PlaybackStateCompat.STATE_PLAYING) {
gesPlaybackController.pause();
} else {
//gesPlaybackController.play();
gesPlaybackController.playFromMediaId(String.valueOf(R.raw.warner_tautz_off_broadway), null);
}
break;
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case REQUEST_CODE_GESPLAYER_EXTERNAL_STORAGE: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "onRequestPermissionResult: granted", Toast.LENGTH_SHORT).show();
} else {
//close the app if permissions aren't granted
//Toast.makeText(this, "onRequestPermissionResult: denied", Toast.LENGTH_SHORT).show();
finish();
}
return;
}
// other 'case' lines to check for other
// permissions this app might request.
}
}
列。
有谁知道如何实现
答案 0 :(得分:1)
如果你使用Pandas 0.15或以上,你可以利用这样的dt
访问者
df['Year'] = df['Date'].year
df['Month'] = df['Date'].month
df['Day'] = df['Date'].day