-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpytecplot_with_pandas.py
More file actions
24 lines (21 loc) · 917 Bytes
/
Copy pathpytecplot_with_pandas.py
File metadata and controls
24 lines (21 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pandas
import tecplot
def pandas_to_zone(df,dataset,zone_name='pandas'):
"""Adds a zone and populates the variables from a pandas dataframe.
Make sure the column keys match the variable names.
See also zone_to_pandas().
"""
dfzone = dataset.add_ordered_zone(zone_name,df.shape[0])
for k in df.keys():
kglob = k[:k.find('[')] + '[[]' + k[k.find('[')+1:k.find(']')] + '[]]' + k[k.find(']')+1:]
dfzone.values(kglob)[:] = df[k].values
return dataset
def zone_to_pandas(zone, variables, df_index=None):
"""Exports the variables in a zone to a pandas dataframe.
variables should be, eg., the iterable result of dataset.variables()
See also pandas_to_zone(). Please use caution when working with large
datasets.
"""
vardict = {var.name : zone.values(var.index)[:] for var in variables}
df = pd.DataFrame(vardict,index=df_index)
return df