I think I might understand now. I think your screenshot does not really apply to your question. In your screenshot you show a dataframe where the first column (column 0) is named sensor_00. I thought you wanted to rename the leftmost column of row index names. This is not a column, so it cannot be named. You can rename the axis, but the numbers [0, 1, 2, 3, ...] are row index names, not data.
Later you mention reading a csv file. I looked back at your original post and added this information to better understand how can you rename "Unamed:0". Now your question makes more sense. You wrote a dataframe to a CSV file and read it back. This added a new, unnamed column to the dataframe.
DataFrame.to_csv() has an "index" to write the column index or not. From the docs:
Quote:indexbool, default True
Write row names (index).
I always set this to False when writing a CSV. This creates a CSV file without the row index labels. This is better for opening in Excel, and I can easily reload the dataframe from the CSV file.
df.to_csv(filename, index=None)
df = pd.read_csv(filename)
pandas.read_csv() has a similar argument, index col. From the docs:
Quote:index_colint, str, sequence of int / str, or False, optional, default None
Column(s) to use as the row labels of the DataFrame, either given as string name or column index. If a sequence of int / str is given, a MultiIndex is used.
Note: index_col=False can be used to force pandas to not use the first column as the index, e.g. when you have a malformed file with delimiters at the end of each line.
If I include row index labels in the CSV, I can use this option to tell pandas that the first column in the CSV file are the row index values, not the first column of the dataframe.
df.to_csv(filename) # Will write row index values to file
df = pd.read_csv(filename, index_col=0) # Tell pandas the first "column" is the row index values
You want to avoid doing this:
df.to_csv(filename) # Writes row index values to CSV file
df = pd.read_csv(filename) # Treat first column in CSV file as data, not an index
Now the dataframe has an extra, unnamed column at the front.
You can give the column a name.
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("data.txt").rename(columns={"Unnamed: 0": "Time"})
print(df)
Output:
Time A B C
0 0 2 5 5
1 1 1 1 5
2 2 4 4 3
This gives the column a name, but you've now promoted index values to the status of data.