我正在尝试重新采样此 Dataframe 的Timestamp列:
Transit.head():
Timestamp Plate Gate
0 2013-11-01 21:02:17 4f5716dcd615f21f658229a8570483a8 65
1 2013-11-01 16:12:39 0abba297ac142f63c604b3989d0ce980 64
2 2013-11-01 11:06:10 faafae756ce1df66f34f80479d69411d 57
Run Code Online (Sandbox Code Playgroud)
这就是我所做的:
Transit.drop_duplicates(inplace=True)
Transit.Timestamp = pd.to_datetime(Transit.Timestamp)
Transit['Timestamp'].resample('1H').pad()
Run Code Online (Sandbox Code Playgroud)
但我收到了这个错误:
Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Int64Index'
Run Code Online (Sandbox Code Playgroud)
任何建议将不胜感激。
我有一个包含此列的数据框:
Mi_Meteo['Time_Instant'].head():
0 2013/11/14 17:00
1 2013/11/14 18:00
2 2013/11/14 19:00
3 2013/11/14 20:00
4 2013/11/14 21:00
Name: Time_Instant, dtype: object
Run Code Online (Sandbox Code Playgroud)
做了一些检查后,我意识到:
Mi_Meteo['Time_Instant'].value_counts():
2013/12/09 02:00 33
2013/12/01 22:00 33
2013/12/11 10:00 33
2013/12/05 09:00 33
.
.
.
.
2013/11/16 02:00 21
2013/11/07 10:00 11
2013/11/17 22:00 11
DateTIme 3
Run Code Online (Sandbox Code Playgroud)
所以我把它条纹了:
Mi_Meteo['Time_Instant'] = Mi_Meteo['Time_Instant'].str.rstrip('DateTIme')# Cause Otherwise I would get this Error When Converting : 'Unknown string format'
Run Code Online (Sandbox Code Playgroud)
然后我尝试转换它:
Mi_Meteo['Time_Instant'] = pd.to_datetime(Mi_Meteo['Time_Instant'])
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
String does not contain a date.
Run Code Online (Sandbox Code Playgroud)
任何建议将不胜感激,谢谢大家。
我正在尝试使用此函数将多个 CSV 文件合并为一个:
import glob
path = r'/content/drive/My Drive/DatiAirQuality/MI_Air_Quality/data'
all_files = glob.glob(path + "/*.csv")
li = []
for filename in all_files:
df = pd.read_csv(filename, index_col=None, header=0)
li.append(df)
frame = pd.concat(li, axis=0, ignore_index=True)
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:“utf-8”编解码器无法解码位置 0 中的字节 0xb5:无效的起始字节
这是回溯:
8 for filename in all_files:
----> 9 df = pd.read_csv(filename, index_col=None,
header=0)
10 li.append(df)
11
Run Code Online (Sandbox Code Playgroud)
感谢你。
dataframe ×2
pandas ×2
csv ×1
date ×1
datetime ×1
python ×1
python-3.x ×1
resampling ×1
string ×1
utf-8 ×1