要从目录中读取文件,请尝试以下操作:
import os
import pandas as pd
path=os.getcwd()
files=os.listdir(path)
files
['wind-diciembre.xls', 'stat_noviembre.xls', 'stat_marzo.xls', 'wind-noviembre.xls', 'wind-enero.xls', 'stat_octubre.xls', 'wind-septiembre.xls', 'stat_septiembre.xls', 'wind-febrero.xls', 'wind-marzo.xls', 'wind-julio.xls', 'wind-octubre.xls', 'stat_diciembre.xls', 'stat_julio.xls', 'wind-junio.xls', 'stat_abril.xls', 'stat_enero.xls', 'stat_junio.xls', 'stat_agosto.xls', 'stat_febrero.xls', 'wind-abril.xls', 'wind-agosto.xls']
Run Code Online (Sandbox Code Playgroud)
哪里:
stat_enero
Fecha HR PreciAcu RadSolar T Presion Tmax HRmax \
01/01/2011 37 0 162 18.5 0 31.2 86
02/01/2011 70 0 58 12.0 0 14.6 95
03/01/2011 62 0 188 15.3 0 24.9 86
04/01/2011 69 0 181 17.0 0 29.2 97
.
.
.
Presionmax RadSolarmax …Run Code Online (Sandbox Code Playgroud) 以下脚本尝试计算风的方向和幅度的平均值.我的月度数据框包含以下列:
data
Fecha Hora DirViento MagViento Temperatura Humedad PreciAcu
0 2011/07/01 00:00 318 6.6 21.22 100 1.7
1 2011/07/01 00:15 342 5.5 21.20 100 1.7
2 2011/07/01 00:30 329 6.6 21.15 100 4.8
3 2011/07/01 00:45 279 7.5 21.11 100 4.2
4 2011/07/01 01:00 318 6.0 21.16 100 2.5
Run Code Online (Sandbox Code Playgroud)
我做的第一件事就是将DirViento列转换为弧度
dir_rad=[]
for i in range(0, len(data['DirViento'])):
dir_rad.append(data['DirViento'][i]*(pi/180.0))
data['DirViento']=around(dir_rad,1)
Run Code Online (Sandbox Code Playgroud)
现在获取组件的列:u和v wind并添加到数据中
Uviento=[]
Vviento=[]
for i in range(0,len(data['MagViento'])):
Uviento.append(data['MagViento'][i]*sin(data[DirViento][i]))
Vviento.append(data['MagViento'][i]*cos(data[DirViento][i]))
data['u']=around(Uviento,1)
data['v']=around(Vviento,1)
data
Data columns:
Fecha 51 non-null values
Hora 51 non-null …Run Code Online (Sandbox Code Playgroud) 我有一个包含以下列的数据框:
file['DirViento']
Fecha
2011-01-01 ENE
2011-01-02 ENE
2011-01-03 ENE
2011-01-04 NNE
2011-01-05 ENE
2011-01-06 ENE
2011-01-07 ENE
2011-01-08 ENE
2011-01-09 NNE
2011-01-10 ENE
2011-01-11 ENE
2011-01-12 ENE
2011-01-13 ESE
2011-01-14 ENE
2011-01-15 ENE
...
2011-12-17 ENE
2011-12-18 ENE
2011-12-19 ENE
2011-12-20 ENE
2011-12-21 ENE
2011-12-22 ENE
2011-12-23 ENE
2011-12-24 ENE
2011-12-25 ENE
2011-12-26 ESE
2011-12-27 ENE
2011-12-28 NE
2011-12-29 ENE
2011-12-30 NNE
2011-12-31 ENE
Name: DirViento, Length: 290, dtype: object
Run Code Online (Sandbox Code Playgroud)
该列每日记录每个月的风向.我正努力争取每个月的主导方向.要完成此操作,请选择月内最常重复的数据:
file['DirViento'].groupby(lambda x: x.month).value_counts()
1 ENE 23
NNE 6
E …Run Code Online (Sandbox Code Playgroud) 我有一个数据框,其中行代表一天中的小时,列代表时间频率。目的是创建一个 3D 条形图,每列代表不同的颜色。我的数据框如下
frec=pd.read_csv('tiempo.csv', parse_dates='Horas',index_col='Horas')
frec.index=[date.strftime('%H:%M') for date in frec.index]
frec
Inicio MaxExt Fin
18:00 1 1 1
19:00 0 0 3
20:00 1 1 1
21:00 1 1 0
22:00 3 1 0
23:00 9 1 0
00:00 8 3 2
01:00 2 0 1
02:00 3 8 1
03:00 5 3 2
04:00 6 2 6
05:00 6 6 5
06:00 5 6 4
07:00 5 7 2
08:00 2 4 5
09:00 1 6 6
10:00 0 …Run Code Online (Sandbox Code Playgroud) import numpy as np
data = np.loadtxt('path-tracks.csv',dtype=np.str,delimiter=',',skiprows=1)
print data
[['19.70' '-95.20' '2/5/04 6:45 AM' '1' '-38' 'CCM']
['19.70' '-94.70' '2/5/04 7:45 AM' '1' '-48' 'CCM']
['19.30' '-93.90' '2/5/04 8:45 AM' '1' '-60' 'CCM']
['19.00' '-93.50' '2/5/04 9:45 AM' '1' '-58' 'CCM']
['19.00' '-92.80' '2/5/04 10:45 AM' '1' '-50' 'CCM']
['19.20' '-92.60' '2/5/04 11:45 AM' '1' '-40' 'CCM']
['19.90' '-93.00' '2/5/04 12:45 PM' '1' '-43' 'CCM']
['20.00' '-92.80' '2/5/04 1:15 PM' '1' '-32' 'CCM']
['23.10' '-100.20' '30/5/04 4:45 AM' '2' '-45' …Run Code Online (Sandbox Code Playgroud) 我有下一个DataFrame:
data=pd.read_csv('anual.csv', parse_dates='Fecha', index_col=0)
data
DatetimeIndex: 290 entries, 2011-01-01 00:00:00 to 2011-12-31 00:00:00
Data columns (total 12 columns):
HR 290 non-null values
PreciAcu 290 non-null values
RadSolar 290 non-null values
T 290 non-null values
Presion 290 non-null values
Tmax 290 non-null values
HRmax 290 non-null values
Presionmax 290 non-null values
RadSolarmax 290 non-null values
Tmin 290 non-null values
HRmin 290 non-null values
Presionmin 290 non-null values
dtypes: float64(4), int64(8)
Run Code Online (Sandbox Code Playgroud)
哪里:
data['HR']
Fecha
2011-01-01 37
2011-02-01 70
2011-03-01 62
2011-04-01 69 …Run Code Online (Sandbox Code Playgroud) 我有 el 下一个数据框
data=read_csv('enero.csv')
data
Fecha DirViento MagViento
0 2011/07/01 00:00 318 6.6
1 2011/07/01 00:15 342 5.5
2 2011/07/01 00:30 329 6.6
3 2011/07/01 00:45 279 7.5
4 2011/07/01 01:00 318 6.0
5 2011/07/01 01:15 329 7.1
6 2011/07/01 01:30 300 4.7
7 2011/07/01 01:45 291 3.1
Run Code Online (Sandbox Code Playgroud)
如何将Fecha列拆分为两列,例如得到一个dataframe如下:
Fecha Hora DirViento MagViento
0 2011/07/01 00:00 318 6.6
1 2011/07/01 00:15 342 5.5
2 2011/07/01 00:30 329 6.6
3 2011/07/01 00:45 279 7.5
4 2011/07/01 01:00 318 6.0
5 2011/07/01 …Run Code Online (Sandbox Code Playgroud)